background image

Nondurable Subscribers and Subscriptions

<< The createDurableSubscriber Method | A Durable Subscription Example >>
<< The createDurableSubscriber Method | A Durable Subscription Example >>

Nondurable Subscribers and Subscriptions

subscription also ends. Here, create stands for a call to Session.createConsumer with a Topic
argument, and close stands for a call to MessageConsumer.close. Any messages published to
the topic between the time of the first close and the time of the second create are not
consumed by the subscriber. In
Figure 31­7
, the subscriber consumes messages M1, M2, M5,
and M6, but messages M3 and M4 are lost.
With a durable subscriber, the subscriber can be closed and re-created, but the subscription
continues to exist and to hold messages until the application calls the unsubscribe method. In
Figure 31­8
, create stands for a call to Session.createDurableSubscriber, close stands for
a call to MessageConsumer.close, and unsubscribe stands for a call to Session.unsubscribe.
Messages published while the subscriber is closed are received when the subscriber is created
again. So even though messages M2, M4, and M5 arrive while the subscriber is closed, they are
not lost.
See
"A Java EE Application That Uses the JMS API with a Session Bean" on page 964
for an
example of a Java EE application that uses durable subscriptions. See
"A Message
Acknowledgment Example" on page 938
and the next section for examples of client
applications that use durable subscriptions.
Subscriber
Subscription
create
close
Subscriber
Subscription
create
close
M1
M2
M3
M4
M5
M6
FIGURE 31­7
Nondurable Subscribers and Subscriptions
Subscriber
create
close
M1
M2
M3
M4 M5
M6
Subscriber
create
close
Subscriber
create
close
create
unsubscribe
FIGURE 31­8
A Durable Subscriber and Subscription
Creating Robust JMS Applications
The Java EE 5 Tutorial · September 2007
944