background image

Publish Subscribe Messaging Domain

<< Messaging Domains | The JMS API Programming Model >>
<< Messaging Domains | The JMS API Programming Model >>

Publish Subscribe Messaging Domain

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.
Use PTP messaging when every message you send must be processed successfully by one
consumer.
Publish/Subscribe Messaging Domain
In a publish/subscribe (pub/sub) product or application, clients address messages to a topic,
which functions somewhat like a bulletin board. Publishers and subscribers are generally
anonymous and can 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 can 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 subscribers to create
durable subscriptions, which 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, see
"Creating
Durable Subscriptions" on page 942
.
Use pub/sub messaging when each message can be processed by zero, one, or many consumers.
Figure 31­4
illustrates pub/sub messaging.
Sends
Msg
Client 1
Queue
Msg
Consumes
Client 2
Acknowledges
FIGURE 31­3
Point-to-Point Messaging
Basic JMS API Concepts
Chapter 31 · The Java Message Service API
899