Chapter 7. Application and system design guidelines 199
ConnectionFactory is used to create a connection with the provider.
Destination is used to access a source or destination of messages.
Both are required for the JMS client to send a message.
7.5.1 Message models
Each messaging model has a set of interfaces in JMS that define specialized
operations for that model. There are two domains defined in the JMS
specification for messaging applications:
򐂰 Point-to-point (PTP)
򐂰 Publish/subscribe (pub/sub)
JMS is based on some common messaging concepts which are defined in JMS
parent classes. See Figure 7-25. Each messaging domain defines a customized
set of these classes for its own domain. There are also classes defined that are
transaction aware, such as XAQueueConnection Factory.
Figure 7-25 JMS classes
Publish/subscribe messagingPoint-to-point messaging
«JavaInterface»
ConnectionFactor
y
«JavaInterface»
TopicConnection
Factory
«JavaInterface»
XAQueue
ConnectionFactory
«JavaInterface»
XATopicConnection
Factory
«JavaInterface»
QueueConnection
Factory
«Jav aInterfac
Connection
«JavaInterface»
QueueConnection
«Jav aInterface»
XAQueue
Connection
«JavaInterface»
X
ATopicConnectio
n
«Jav aInterfac
TopicConnection
«Jav aInterfac
Session
«JavaInterface»
QueueSession
«Jav aInterface»
TopicSession
«JavaInterface»
XAQueueSession
«JavaInterface»
X
ATopicSessio
n
«Jav aInterface»
Queue
«Jav aInterface»
Topic
«JavaInterface»
MessageConsumer
«Jav aInterfac
MessageProducer
«Jav aInterface»
Destination
«JavaInterface»
QueueReceiver
«Jav aInterface»
QueueSender
«JavaInterface»
T
opicPublishe
r
«JavaInterface»
TopicSubscriber
«JavaInterface»
Message
200 Patterns: Implementing Self-Service in an SOA Environment
The JMS parent classes define the following basic message concepts:
򐂰 ConnectionFactory is an administrative object used by a client to create a
connection.
򐂰 Connection is an active connection to a JMS provider.
򐂰 Destination is an administrative object encapsulating the identity of a
message destination.
򐂰 Session is a single-threaded context for sending and receiving messages.
򐂰 MessageProducer is an object created by a Session for sending messages to
a Destination.
򐂰 MessageConsumer is an object created by a Session for receiving messages
from a Destination.
Not all JMS objects can be used concurrently. Table 7-3 shows the objects that
can be used concurrently and those that cannot.
Table 7-3 Concurrent JMS classes
There are two reasons for restricting concurrent access to sessions. First,
sessions are the JMS entities that support transactions. It is very difficult to
implement transactions that are multi-threaded. Second, sessions support
asynchronous message consumption. If a session has been set up with multiple,
asynchronous consumers, it is important that these separate consumers do not
execute concurrently.
JMS point-to-point model
Point-to-point (PTP) messaging in Figure 7-26 on page 201 involves working with
queues of messages. The sender sends messages to a specific queue to be
consumed normally by a single receiver. In point-to-point communication, a
message has at most one recipient. A sending client addresses the message to
the queue that holds the messages for the intended or receiving client. You can
think of the queue as a mailbox. Many clients might send messages to the
Object Concurrent use
ConnectionFactory Yes
Connection Yes
Destination Yes
Session No
MessageProducer No
MessageConsumer No
Chapter 7. Application and system design guidelines 201
queue, but a message is taken out by only one client. Like a mailbox, messages
remain in the queue until they are removed. Thus the availability of the recipient
client does not affect the ability to deliver a message. In a point-to-point system,
a client can be a sender (message producer), a receiver (message consumer), or
both. In JMS, PTP types are prefixed with
Queue.
Figure 7-26 JMS point-to-point model
JMS publish/subscribe model
In contrast to the point-to-point model of communication, the publish/subscribe
model, shown in Figure 7-27, enables the delivery of a message to multiple
recipients. A sending client addresses, or publishes, the message to a topic to
which multiple clients can be subscribed. There can be multiple publishers, as
well as subscribers, to a topic. A durable (or persistent) subscription, or interest,
exists across client shutdowns and restarts. While a client is down, all objects
that are delivered to the topic are stored and then sent to the client when it
renews the subscription. A non-durable subscription will deliver messages when
the consumer is connected, but discard messages when the consumer is not
connected. In a publish/subscribe system, a client can be a publisher (message
producer), a subscriber (message consumer), or both. In JMS, pub/sub types are
prefixed with
Topic.
Figure 7-27 Publish/subscribe model
JMS also supports the optional durability of subscribers and remembers that they
exist while they are inactive. All an application has to do is send information it
wants to share to a standard destination managed by the JMS provider
publish/subscribe, and let the JMS provider publish/subscribe distribute it.
JMS Client
Sends
Sender
Consumes
Receiver
Queue
Msg
Msg
JMS Client
Subscribes
Subscriber
JMS Client
JMS Client
JMS Client
Publishes
Publisher
Topic

Get Patterns: Implementing Self-Service in an SOA Environment now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.