background image

A Durable Subscription Example

<< Nondurable Subscribers and Subscriptions | Connection Factory without Client ID >>
<< Nondurable Subscribers and Subscriptions | Connection Factory without Client ID >>

A Durable Subscription Example

A Durable Subscription Example
The DurableSubscriberExample.java program shows how durable subscriptions work. It
demonstrates that a durable subscription is active even when the subscriber is not active. The
program contains a DurableSubscriber class, a MultiplePublisher class, a main method, and
a method that instantiates the classes and calls their methods in sequence.
The program is in the following directory:
tut-install/javaeetutorial5/examples/jms/advanced/durablesubscriberexample/src/java/
The program begins in the same way as any publish/subscribe program: The subscriber starts,
the publisher publishes some messages, and the subscriber receives them. At this point, the
subscriber closes itself. The publisher then publishes some messages while the subscriber is not
active. The subscriber then restarts and receives the messages.
Before you run this program, compile and package the source file and create a connection
factory that has a client ID. Perform the following steps:
1. To compile and package the program using NetBeans IDE, follow these steps:
a. In NetBeans IDE, choose Open Project from the File menu.
b. In the Open Project dialog, navigate to
tut-install/javaeetutorial5/examples/jms/advanced/.
c. Select the durablesubscriberexample folder.
d. Select the Open as Main Project check box.
e. Click Open Project Folder.
f. Right-click the project and choose Build Project.
To compile and package the program using Ant, follow these steps:
a. Go to the following directory:
tut-install/javaeetutorial5/examples/jms/advanced/durablesubscriberexample/
b. Type the following command:
ant
2. If you did not do so for
"A Message Acknowledgment Example" on page 938
, create a
connection factory named jms/DurableConnectionFactory:
ant create-durable-cf
To run the program using NetBeans IDE, right-click the durablesubscriberexample project
and choose Run Project.
Creating Robust JMS Applications
Chapter 31 · The Java Message Service API
945