background image

The JMS API Programming Model

<< Publish Subscribe Messaging Domain | JMS Administered Objects >>
<< Publish Subscribe Messaging Domain | JMS Administered Objects >>

The JMS API Programming Model

Programming with the Common Interfaces
Version 1.1 of the JMS API allows you to use the same code to send and receive messages under
either the PTP or the pub/sub domain. The destinations that you use remain domain-specific,
and the behavior of the application will depend in part on whether you are using a queue or a
topic. However, the code itself can be common to both domains, making your applications
flexible and reusable. This tutorial describes and illustrates these common interfaces.
Message Consumption
Messaging products are inherently asynchronous: There is no fundamental timing dependency
between the production and the consumption of a message. However, the JMS specification
uses this term in a more precise sense. 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.
The JMS API Programming Model
The basic building blocks of a JMS application consist of
Administered objects: connection factories and destinations
Connections
Sessions
Message producers
Message consumers
Publishes
Msg
Client 1
Topic
Msg
Subscribes
Client 2
Delivers
Subscribes
Client 3
Delivers
FIGURE 31­4
Publish/Subscribe Messaging
The JMS API Programming Model
The Java EE 5 Tutorial · September 2007
900