A Story of JMS

One day Minnie was walking down a street in Paris when she heard Mickey calling her

Mickey – Hey Minnie, wait!

Minnie – Hi Mickey, what happened

Mickey – I need to talk to you

Minnie – Yes tell me

Mickey – Do you know about JMS

Minnie – Yes I know

Mickey – Can you explain this to me in very simple language from scratch

Minnie – Mickey lets go to the Eiffel Tower and I will tell you a story

Mickey – Great! Let’s Go

(Mickey and Minnie at Eiffel Tower)

Mickey – It feels so good here

Minnie – I know

Mickey – So shall we start

Minnie – Yes to start with JMS = Java Messaging Service

Mickey – I know that

Minnie – JMS is an API that provides the facility to create, send and read messages

Mickey – I do not get this. Why and where is this used? Start from scratch

Minnie – Okay so let us first understand Messaging

Mickey – Okay

Minnie – Messaging is a process to communicate between applications. JMS is used to send and receive messages from one application to another

Mickey – Okay, I got that JMS is used for communication between applications, but why do we need this in the first place

Minnie – Today we use distributed application development. So when you see a product like a website, at the backend there are multiple components or apps working together. Now there needs to be a process of communication between these elements or applications. JMS provides this feature

Mickey – I am getting this

Minnie – And JMS follows the asynchronous method of communication

Mickey – Now what is this new term

Minnie – Okay let us understand Synchronous and Asynchronous method

Mickey – Yes, please

Minnie – Suppose you are working on your computer. You need to take a print. You will give print command. The printer will inform you that printing is in process and you can continue working on other things, while the printing is in process. Once done you will get a message that your document is printed

Mickey – Yes I know this

Minnie – So this is the Asynchronous method. Here the response is sent to the user before the execution completes. This is very useful in long-running background processes. As the response is sent about the status of the process, the user can perform other tasks, while the process is in progress.

Synchronous means things are getting done in sequential order. This means if one process is going on, another one won’t start unless the already running process is finished.

In Synchronous method, the response is sent only after completion of the process

Mickey – Great! Give me a real example

Minnie – Have you noticed, sometimes while browsing, if some request is stuck or not completed, the browser becomes unresponsive and you cannot proceed.

Mickey – Yeah, that used to happen a lot earlier

Minnie – Yes, so that was the classic web application model, that was Synchronous but today we use technologies like AJAX to overcome this

Mickey – So AJAX is asynchronous

Minnie – Yes, but more on that some other day. Let’s focus on JMS today

Mickey – yeah, So I got that JMS is a messaging service for communication between applications and uses the asynchronous method for communication

Minnie – Great

Mickey – But where does this come from. Is it a separate software or application

Minnie – JMS is part of Java EE. So if you have Java Enterprise Edition on your system, you have JMS

Mickey – Okay

Minnie – So it is an API in Java and allows to create, send, receive, and read messages

Mickey – Now how does this message or data of communication look like

Minnie It can be a text, XML document, JSON data or an Entity (Java Object), etc

Mickey – So is JMS API used to implement Messaging systems in Java-based applications only?

Minnie – That is right

Mickey – Okay Minnie before we go further let me tell you my understanding

  1. JMS stands for Java Messaging Service
  2. It is an API included in the Java EE package
  3. It is used for communication between applications
  4. It uses Asynchronous method of communication
  5. Can be used for Java applications only

Minnie – Wow, you summarised well and to add to this

JMS can perform the following tasks

  1. Create message
  2. Send message
  3. Receive message
  4. Read message

Mickey – Thanks Minnie

Minnie – Now there are to types or model of JMS

  1. Point-to-point
  2. Publish/Subscribe

Point-to-point

In the point-to-point message bean, we have one sender and one receiver. It is like a personal chat on mobile, but this messaging is between components. When the sender sends a message, if there is more than one message, then it has to wait in the queue. Once it reaches a receiver, a receiver can consume it and acknowledge it

  1. There is only one client for each message.
  2. There is no timing dependency for the sender and receiver of a message.
  3. The receiver can fetch the message whether it is running or not when the sender sends the message.
  4. The receiver sends the acknowledgment after receiving the message.
  5. Queue is used as message-oriented middleware (MOM)

Publish/Subscriber (One-to-Many)

In Pub/Sub model, one message is delivered to all the subscribers. It is like broadcasting.

Publish/subscriber is like Netflix. With Netflix, we have one provider (sender) and many consumers (receiver). Many users can subscribe to Netflix and watch a T.V. show or movie uploaded by Netflix. This is the same way as with the publish/ subscriber; the first component needs to subscribe. After subscribing, the component can consume and acknowledge messages. If there is more than one message, then it has to wait on a topic

  1. There can be multiple subscribers for a message.
  2. The publisher and subscribe have a timing dependency. A client that subscribes to a topic can consume only messages published after the client has created a subscription, and the subscriber must continue to be active in order for it to consume messages.
  3. Topic is used as a message-oriented middleware that is responsible to hold and deliver messages.

Mickey – Great to know this

Minnie – Do you want to go home now

Mickey – No Minnie let us sit here and watch the sunset

Minnie – Sure

Mickey – Thanks, I feel so good now

Minnie – I am always here for you 🙂

about the author more stories

References
https://www.javatpoint.com/jms-tutorial
https://dzone.com/articles/java-message-service-1
https://howtodoinjava.com/jms/jms-java-message-service-tutorial/#need
https://www.cavisson.com/netstorm-java-messaging-service/

28