JMS Introduction


Messaging enables distributed communication that is loosely coupled. A component sends a message to a destination, and the recipient can retrieve the message from the destination. However, the sender and the receiver do not have to be available at the same time in order to communicate. In fact, the sender does not need to know anything about the receiver; nor does the receiver need to know anything about the sender. The sender and the receiver need to know only what message format and what destination to use. In this respect, messaging differs from tightly coupled technologies, such as Remote Method Invocation (RMI), which require an application to know a remote application’s methods.

A JMS application is composed of the following parts.

  • A JMS provider is a messaging system that implements the JMS interfaces and provides administrative and control features. An implementation of the JEE platform usually includes a JMS provider.
  • JMS clients are the programs written in the Java that produce and consume messages.
  • JMS Destinations are Queue for a point-to-point messaging and Topic for pub/sub messaging.
  • Messages are the objects that communicate information between JMS clients and destinations.
  • Administered objects are pre-configured JMS objects created by a server administrator for the use of messaging clients. The two kinds of administered objects are destinations and connection factories
What is the difference between point-to-point and the publish/subscribe approach to messaging? Or, in other words, what is the difference between a Queue and a Topic?
A point-to-point (PTP) model is built around the concept of message queues, senders, and receivers. Each message is addressed to a specific queue, and receiving clients extract messages from the queue(s) established to hold their messages. Queues retain all messages sent to them until the messages are consumed or until the messages expire.

Point-to-Point messaging has the following characteristics.

  • Each message has only one consumer.
  • A sender and a receiver of a message have no timing dependencies. The receiver can fetch the message whether or not it was running when the client sent the message.
  • The receiver acknowledges the successful processing of a message.

PTP messaging should be used when every message you send must be processed successfully by one consumer.

In a publish/subscribe (pub/sub) model, clients address messages to a topic. Publishers and subscribers are generally anonymous and may dynamically publish or subscribe to the content hierarchy. The system takes care of distributing the messages arriving from a topic’s multiple publishers to its multiple subscribers. Topics retain messages only as long as it takes to distribute them to current subscribers.
Pub/sub messaging has the following characteristics.

  • Each message may have multiple consumers.
  • Publishers and subscribers 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.

The JMS API relaxes this timing dependency to some extent by allowing clients to create durable subscriptions. Durable subscriptions can receive messages sent while the subscribers are not active. Durable subscriptions provide the flexibility and reliability of queues but still allow clients to send messages to many recipients. For more information about durable subscriptions

Pub/sub messaging should be when each message can be processed by zero, one, or many consumers.

If Messaging is by definition asynchronous, what does synchronous message consumption mean?
Messaging applications are inherently asynchronous in that no fundamental timing dependency exists between the production and the consumption of a message. However, the JMS Specification uses this term in the conetxt of its API. Messages can be consumed in either of two ways:

Synchronously. A subscriber or a receiver explicitly fetches the message from the destination by calling the receive() method. The receive method can block until a message arrives or can time out if a message does not arrive within a specified time limit.

Asynchronously. A client can register a message listener with a consumer. A message listener is similar to an event listener. Whenever a message arrives at the destination, the JMS provider delivers the message by calling the listener’s onMessage() method, which acts on the contents of the message.

0 Response to “JMS Introduction”


Leave a Reply