Java Reference
In-Depth Information
At the cost of higher overhead, you can use the Ses-
sion.createDurableSubscriber method to create a durable subscriber. A dur-
able subscription can have only one active subscriber at a time.
A durable subscriber registers a durable subscription by specifying a unique identity that
is retained by the JMS provider. Subsequent subscriber objects that have the same identity
resume the subscription in the state in which it was left by the preceding subscriber. If a
durable subscription has no active subscriber, the JMS provider retains the subscription's
messages until they are received by the subscription or until they expire.
You establish the unique identity of a durable subscriber by setting the following:
• A client ID for the connection
• A topic and a subscription name for the subscriber
You set the client ID administratively for a client-specific connection factory using either
the command line or the Administration Console.
After using this connection factory to create the connection and the session, you call the
createDurableSubscriber method with two arguments: the topic and a string that
specifies the name of the subscription:
Click here to view code image
String subName = "MySub";
MessageConsumer topicSubscriber =
session.createDurableSubscriber(myTopic, subName);
The subscriber becomes active after you start the Connection or TopicConnec-
tion . Later, you might close the subscriber:
topicSubscriber.close();
The JMS provider stores the messages sent or published to the topic, as it would store mes-
sages sent to a queue. If the program or another application calls createDurableSub-
scriber using the same connection factory and its client ID, the same topic, and the
same subscription name, then the subscription is reactivated and the JMS provider deliv-
ers any messages that were published while the subscriber was inactive.
To delete a durable subscription, first close the subscriber, then use the unsubscribe
method with the subscription name as the argument:
topicSubscriber.close();
session.unsubscribe("MySub");
The unsubscribe method deletes the state the provider maintains for the subscriber.
Search WWH ::




Custom Search