About Bilgin Ibryam

Bilgin Ibryam is a senior software engineer based in London interested in service-oriented architecture, enterprise application integration and application development. He is also open source enthusiast, Apache Open for Business and Apache Camel committer.

Publish/Subscribe Pattern with Apache Camel

Publish/Subscribe is a simple messaging pattern where a publisher sends messages to a channel without the knowledge of who is going to receive them. Then it is the responsibility of the channel to deliver a copy of the messages to each subscriber. This messaging model enables creation of loosely coupled and scalable systems.
 
 
 
 
 
 

It is a very common messaging pattern and there are so many ways to create a kind of pub-sub in Apache Camel. But bear in mind that they are all different and have different characteristics. From the simplest to more complex, here is a list:

  • Multicast – works only with a static list of subscribers, can deliver the message to subscriber in parallel, stops or continues on exception if one of the subscribers fails.
  • Recipient List – it is similar to multicast, but allows the subscribers to be defined at run time, for example in the message header.
  • SEDA – this component provides asynchronous SEDA behaviour using BlockingQueue. When multipleConsumers option is set, it can be used for asynchronous pub-sub messaging. It also has possibilities to block when full, set queue size or time out publishing if the message is not consumed on time.
  • VM – same as SEDA, but works cross multiple CamelContexts, as long as they are in the same JMV. It is a nice mechanism for sending messages between webapps in a web-container or bundles in OSGI container.
  • Spring-redis – Redis has pubsub feature which allows publishing messages to multiple receivers. It is possible to subscribe to a channel by name or using pattern-matching. When pattern-matching is used, the subscriber will receive messages from all the channels matching the pattern. Keep in mind that in this case it is possible to receive a message more than once, if the multiple patterns matches the same channel where the message was sent.
  • JMS (ActiveMQ) – that’s probably the best know way for doing pub-sub including durable subscriptions. For a complete list of features check ActiveMQ website.
  • Amazon SNS/SQS – if you need a really scalable and reliable solution, SNS is the way to go. Subscribing a SQS queue to the topic, turns it into a durable subscriber and allows polling the messages later. The important point to remember in this case is that it is not very fast and most importantly, Amazon doesn’t guarantee FIFO order for your messages.

There are also less popular Camel components which offer publish-subscribe messaging model:

  • websocket – it uses Eclipse Jetty Server and can sends message to all clients which are currently connected.
  • hazelcast – SEDA implements a work-queue in order to support asynchronous SEDA architectures.
  • guava-eventbus – integration bridge between Camel and Google Guava EventBus infrastructure.
  • spring-event – provides access to the Spring ApplicationEvent objects.
  • eventadmin – on OSGi environment to receive OSGI events.
  • xmpp – implements XMPP (Jabber) transport. Posting a message in chat room is also pub-sub;)
  • mqtt – for communicating with MQTT compliant message brokers.
  • amqp – supports the AMQP protocol using the Client API of the Qpid project.
  • javaspace – a transport for working with any JavaSpace compliant implementation.

Can you name any other way for doing publish-subscribe?
 

Reference: Publish/Subscribe Pattern with Apache Camel from our JCG partner Bilgin Ibryam at the OFBIZian blog.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.

One Response to "Publish/Subscribe Pattern with Apache Camel"

  1. Richard Dowling-Long says:

    Email :-)

Leave a Reply


+ 1 = six



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy | Contact
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below:
Close