10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Creating Robust JMS Applications<br />

938<br />

FIGURE 31–7 Nondurable Subscribers and Subscriptions<br />

M1 M2 M3 M4 M5 M6<br />

Subscription<br />

Subscriber<br />

create close<br />

With a durable subscriber, the subscriber can be closed and re-created, but the subscription<br />

continues to exist and to hold messages until the application calls the unsubscribe method. In<br />

Figure 31–8, create stands for a call to Session.createDurableSubscriber, close stands for<br />

a call to MessageConsumer.close, and unsubscribe stands for a call to Session.unsubscribe.<br />

Messages published while the subscriber is closed are received when the subscriber is created<br />

again. So even though messages M2, M4, and M5 arrive while the subscriber is closed, they are<br />

not lost.<br />

See “A <strong>Java</strong> <strong>EE</strong> Application That Uses the JMS API with a Session Bean” on page 956 for an<br />

example of a <strong>Java</strong> <strong>EE</strong> application that uses durable subscriptions. See “A Message<br />

Acknowledgment Example” on page 932 and the next section for examples of client<br />

applications that use durable subscriptions.<br />

A Durable Subscription Example<br />

Subscription<br />

Subscriber<br />

create close<br />

FIGURE 31–8 A Durable Subscriber and Subscription<br />

M1 M2 M3 M4 M5 M6<br />

create unsubscribe<br />

Subscriber<br />

create close<br />

Subscriber<br />

create close<br />

Subscriber<br />

create close<br />

<strong>The</strong> DurableSubscriberExample.java program shows how durable subscriptions work. It<br />

demonstrates that a durable subscription is active even when the subscriber is not active. <strong>The</strong><br />

<strong>The</strong> <strong>Java</strong> <strong>EE</strong> 5<strong>Tutorial</strong> • June 2010

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!