JMS

JMS

JMS is nothing but Java Messaging Service. It allows us to achieve asynchronous communication between the parties. Asynchronous communication basically means that the receiver might not be present when the message is sent by the sender.

There are two main ways to achieve this:

1. Queue Based Messaging(Also called point to point messaging)  When there is one sender and one receiver, we normally use queue. The sender sends the message. The message comes to the queue and if the receiver is present, it is sent to the receiver instantly and removed from the queue. However, if the receiver is not present, it is stored in the queue till the receiver comes in. The  message is removed from the queue after delivering to the receiver.

Having said this, what are we going to do if we want to send the message to multiple receiver. Well, Sad to say but we cannot use queue here. Bcoz… the message is removed as soon as it is delivered to 1 receiver. Topic saves our day in such scenarios.

Queue Based Messaging

Queue Based Messaging

2. Topic Based Messaging(Also called publish subscribe model messaging) – In this model, you have a sender publishing a message to a topic and multiple receivers can subscribe to the topic. When the sender sends the message, it goes to the topic. Now suppose we have 3 receivers to that topic, all the three receiver receives the message and the message is removed from the topic. The twist comes when one or more of the subscriber/receiver is not up. In such case, the message is delivered to the receivers who are present and it is stored in the topic till the receivers who are down are up and running. Once the message is delivered to all the receivers, it is removed from the topic. So now all the Subscribers say thank you…’Topic’  🙂

Topic Based Messaging

Topic Based Messaging