Introduction
The Java Message Service (JMS) can be used for communication between components. Features of JMS, such as asynchronous
communication and guaranteed delivery, make it a popular choice for enterprise applications. JMS can be used for
synchronous communication as well, but the asynchronous use is dominant.
These guidelines describe when to use JMS, how to model it, and some applicable design considerations.
For more information on JMS, see Concept: Java Messaging Service (JMS).
Modeling JMS
JMS clients are modeled as classes. The following diagram illustrates a typical interaction of a message producer for
sending messages using JMS. The example is using a queue as a destination.
A JMS client must implement the message listener interface. The JMS provider makes sure that a special method
onMessage is called whenever a message arrives.
The next diagram shows a typical setup of a JMS consumer client.
Designing JMS
There are two main ways of designing JMS applications: point-to-point and publish-subscribe.
In a point-to-point model, JMS is used to deliver a message to ONE client.
Message producers communicate with a message consumer by sending messages to one queue. Conceptually, a queue has only
one consumer, but many JMS providers allow multiple consumers to support load balancing. When multiple consumers are
used, each message is handled by one and only one consumer. Messages are held in the queue until they are consumed or
until they expire.
In a publish-subscribe model, the communication pattern allows multiple producers to send messages to multiple
consumers. Consumers subscribe to topics, and the middleware delivers the messages to the consumers.
In contrast to the point-to-point model, the publish-and-subscribe model keeps the messages in a topic until all the
clients have received it.
Note: Since JMS 1.1 you can combine this two models on the same JMS application.
|