Introduction to Java Messaging Service (JMS)

Java Messaging Service (JMS) API is a specification that allows java programs to create, send and receive messages asynchronously from one application to another. This communication is loosely coupled and very much reliable.

Messages transfer information from one application to another running on a totally different platform.

JMS Provider

JMS Provider is a messaging system that implements the JMS specification. This acts as the Message Oriented Middleware (MOM) which helps in message communication between two systems connected over the network. The message communication, no doubt, is asynchronous and reliable.

Below are some of the popular MOM Service Providers

  • ActiveMQ (Apache)
  • MQSeries (IBM)

Java applications that create and send the message are known as the JMS Producer / Publisher while the applications that receive the message are said to be JMS Consumer/ Subscriber.

The messages that are sent and received can be of any format, maybe in a simple text format, a JSON or an XML. So if we choose the JMS message format to be XML, we can embed a separate component to validate it against an XSD too, which we will take a look some time soon in one of our upcoming articles.

There are two messaging models in JMS –

  1. Point to Point (PTP)
  2. Publisher/ Subscriber (Pub/Sub)

Point to Point (PTP)

This model consists of the message queues, senders, and the receivers. Each message is sent or dispatched to a particular queue by the sender, which is received by the configured listeners on the other side. Queues hold the messages until they are processed or consumed, or until the messages on the queue timeout.

Introduction to JMS - PTP Model

Publisher/ Subscriber (Pub/Sub)

In this model, clients drop messages to a topic.  This topic holds and delivers the message to all the topic subscribers. However, the publisher and subscriber have a timing dependency, such that a client can consume the messages published only after subscribing to a topic and must continue to be active in order to keep consuming the messages on the topic.

Introduction to JMS - PUB/SUB Model

There is no timing dependency in case of PTP, and the receiver can consume the message on the queue even though it was inactive when the message got published.

I hope we all are clear on the very basics and I will soon come up with a working example on JMS to make things even more clear.

Receive our updates to your inbox

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.