ActiveMQ

Using messaging as an integration or communication style leads to many benefits such as:
  1. Allowing applications built with different languages and on different operating systems to integrate with each other    https://activemq.apache.org/cross-language-clients
  2. Location transparency – client applications don’t need to know where the service applications are located
  3. Reliable communication – the producers/consumers of messages don’t have to be available at the same time, or certain segments along the route of the message can go down and come back up without impacting the message getting to the service/consumer
  4. Scaling – can scale horizontally by adding more services that can handle the messages if too many messages are arriving
  5. Asynchronous communication – a client can fire a message and continue other processing instead of blocking until the service has sent a response; it can handle the response message only when the message is ready
  6. Reduced coupling – the assumptions made by the clients and services are greatly reduced as a result of the previous 5 benefits. A service can change details about itself, including its location, protocol, and availability, without affecting or disrupting the client.

The JMS Broker

There is a common misunderstanding that JMS messages are sent directly from one application to another; that the application sending is connected directly to the application receiving. This could not be further from the truth.
Between the sender and receiver (aka producers and consumers) is a broker – an application server – that receives messages from producers and sends messages to consumers. The producers and consumers are completely decoupled. In principle, the producer has no idea who is getting its messages and the consumer has no idea who is sending them.
It’s the broker to which producers are sending the messages using a kind of address called a Topic or Queue. After receiving a message, the broker forwards the message to consumers who have subscribed to the Topic or Queue. Transactions with producers and consumers are transactions between the producer and the broker or between the broker and the consumers, but never between the producer and the consumer.

JMS Topic vs. Queues

With JMS you have the option of publishing messages to a Topic or Queue. There is a fundamental difference between the two which is illustrated below. A Topic forwards a message from the producer to many consumers at once. It’s a broadcast. This is often called Publish-and-Subscribe (Pub/Sub) messaging. A Queue may also have many consumers, but it forwards each message to only one consumer. The consumers wait in line, in a queue, taking turns getting new messages from the Queue. This often called Point-to-Point (P2P) messaging.

Virtual Topics

Virtual topics are a combination of topics and queues. Producers will write messages to a topic while listeners will consume from their own queue. ActiveMQ will copy and duplicate each message from the topic to the actual consumer queues.
This combination of topics and queues has some advantages over conventional topics:
  • Even if a consumer is offline, no messages will be lost. ActiveMQ will copy all messages to the registered queues. As soon as a consumer comes back online, he can handle the messages stored on his queue.
  • If a consumer cannot handle a message, it will put on a dead letter queue. The consumer can be fixed and the message can be put back on his own dedicated queue without affecting the other consumer (as a topic would do).
  • We can register multiple instances of a consumer on a queue to implement a load balancing mechanism.

Comments