<img alt="" src="https://secure.leadforensics.com/150446.png " style="display:none;">
Go to top icon

Java Messaging Service (JMS)

Amit Zambad Oct 03, 2016

RabbitMQ Java Messaging Service (JMS) ActiveMQ

Following JMS providers has been taken into consideration:

ActiveMQ

Features

  • Most Popular JMS provider.
  • It is highly configurable.
  • Has lots of clustering options.
  • Can create network of brokers which provides lots of flexibility.
  • ActiveMQ supports the AMQP 1.0 (Advanced Message Queuing Protocol).
  • ActiveMQ supports the MQTT protocol (machine-to-machine (M2M)/"Internet of Things").
  • Supports pluggable transport protocols such as in-VM, TCP, SSL, NIO, UDP, multicast, JGroups and JXTA transports.
  • Designed for high performance clustering, client-server, peer based communication.
  • REST API to provide technology agnostic and language neutral web based API for messaging.

Drawbacks

  • Less performance as compared to RabbitMQ.
  • Active MQ crashes fairly frequently, at least once per month, and is rather slow.

References

RabbitMQ

Features

  • RabbitMQ offers a variety of features to let you trade off performance with reliability, delivery acknowledgements, including persistence, publisher confirms, and high availability.
  • Queues can be mirrored across several machines in a cluster, ensuring that even in the event of hardware failure your messages are safe.
  • RabbitMQ supports messaging over a variety of messaging protocols.
  • Several RabbitMQ servers on a local network can be clustered together, forming a single logical broker.
  • If your messaging system is misbehaving, RabbitMQ offers tracing support to let you find out what's going on.

Drawbacks

  • DNS errors cause the DB (mnesia) to crash.
  • No ONCE-ONLY semantics. Messages may be sent twice by RabbitMQ to the consumers.
  • Older versions had Unordered; not FIFO delivery. In newer versions the ordered delivery is guaranteed.

References

Suitability of JMS provider for Algorithmic Stock Trading

Problem:- The project involves fetching of data from Cloud and adding it to a JMS Queue. The data from queue is accessed by multiple consumers which will process the data. In this type where data is processed simultaneously, the scenario arises when data related to a particular stock is processed at multiple places. It can happen that newer data gets processed first and older data gets processed later thus breaking the sequence in which data is processed.

Expected Solution:- The data related to a particular stock should be processed by a specific consumer only, who will process the data in a sequence. This avoids the data to be processed simultaneously.

ActiveMQ

ActiveMQ provides the concept of message group. Message Groups are like a parallel exclusive consumer. The standard JMS header JMSXGroupID is used to define which message group the message belongs to. The Message Group feature then ensures that all messages for the same message group will be sent to the same JMS consumer - while that consumer stays alive. As soon as the consumer dies another will be chosen.

Using above concept we can define a message group with the name of the particular stock. The data from this group is sent to a particular consumer only and in sequence. The decision regarding which consumer is to be chosen for a particular message group processing is managed by ActiveMQ. If the consumer processing data fails, another consumer starts processing data. The failover scenario is managed by ActiveMQ automatically.

References

http://activemq.apache.org/message-groups.html

RabbitMQ

In publish subscribe model, RabbitMQ provides the concept of routing. In this model the consumer can ask for particular data using routing key. When a consumer asks for data using the same routing key, the data is sent in sequence.

Using above concept we can define a routing key with the same names as that of particular stock. The consumer can ask for particular data using routing key which is stock name and can receive the stock data related to that particular stock in sequence. The consumer needs to have list of the stocks which it needs to process. In case of consumer breakdown, the programmer needs to implement mechanism through which the stock will be continued to be processed by other consumer.

References

https://www.rabbitmq.com/tutorials/tutorial-four-java.html

 ActiveMQ  RabbitMQ
The decision regarding, distribution of work among consumers is taken by ActiveMQ itself. In RabbitMQ, a particular consumer has to ask the data using the routing key.
In a distributed environment, as the distribution of tasks is managed by ActiveMQ, the load balancing work becomes automatic. In RabbitMQ, the load balancing work has to be managed by the programmer.
In failover scenario, the task is automatically reassigned to other consumer. In failover scenario the programmer has to take care that the processing is reassigned to some other consumer.

Similar Blog

e-Zest is a leading digital innovation partner for enterprises and technology companies that utilizes emerging technologies for creating engaging customers experiences. Being a customer-focused and technology-driven company, it always helps clients in crafting holistic business value for their software development efforts. It offers software development and consulting services for cloud computing, enterprise mobility, big data and analytics, user experience and digital commerce.