JMS is the standard Java API for accessing enterprise messaging products, such as WebSphere MQ (formally MQSeries) and TIBCO. There are two different but complementary approaches to performing enterprise messaging:
-
Point-to-Point: Only one receiver consumes a particular message. An example is one
program telling another to perform a task, such as an investing program telling a brokerage's
system to buy a stock.
- Publish/Subscribe. A copy of each message is delivered to every subscriber. An example is one program notifying others of an event, such as a brokerage broadcasting a stock price.
Figures 1 and 2 (reprinted with permission from Java Message Service, O'Reilly & Associates, 2001) illustrate the difference between these two domains.
Figure 1. Point-to-point messaging
Figure 2. Publish/subscribe messaging
JMS (the
javax.jms package) represents these two approaches using the
interfaces
Queue (point-to-point) and
Topic
(publish/subscribe). They extend the interface
Destination , which
represents a messaging channel that may be either point-to-point or publish/subscribe, as shown
in Figure 3.
Figure 3: The JMS destination hierarchy
A destination acts like an ordered-list data structure -- as messages are added, the destination
lines them up for delivery. A
produceradds messages to the list, whereas a
consumer
removes messages from the list. JMS represents these using the interfaces
MessageProducer and
MessageConsumer ,
respectively.
A
message (the JMS interface
Message ) is a unit of information, such
as a request or a document, to be communicated from a producer to a consumer. When a producer adds a message
to a queue, it is said to
send the message. When a consumer removes a message from a queue, it is said
to
receivethe message.
Messages themselves work the same way in JMS 1.1 that they do in JMS 1.0.2. The difference is the code JMS clients use to send and receive messages.
JMS 1.1 is fully backwards compatible with JMS 1.0.2, so client code written to send and receive
messages using JMS 1.0.2 will work just fine with JMS 1.1. Also, the semantic difference between
the behavior of
Queue implementations and
Topic
implementations has been retained, so point-to-point and publish/subscribe messaging still work the same
as they always have.
Therefore, JMS 1.1 does everything JMS 1.0.2 does. The difference is that JMS 1.1 has
additions to its API so that most client code can treat a channel as a generic
Destination . This is a big improvement over JMS 1.0.2 client code, which has to
treat a channel specifically as a
Topic or a
Queue .