|
Summary: In a durable subscription, if the subscriber is not running messages that it would likely receive are stored by the JMS provider, and delivered when the subscriber is restarted.
OverviewA client that must receive all messages published on a topic, including ones published while the subscriber is inactive, needs a durable TopicSubscriber. The JMS provider retains a record of this durable subscription. This ensures that all messages from the topic's publishers are retained until they are either acknowledged by the durable subscriber or have expired.
Only one session at a time can have a TopicSubscriber for a particular durable subscription.
To create a durable subscription, use one of the createDurableSubscription() methods for the session, as demonstrated below: TopicSubscriber createDurableSubscriber(Topic topic, String subscriptionName) TopicSubscriber createDurableSubscriber(Topic topic, String subscriptionName,String messageSelector, Boolean nolocal) // topicSession is an instance of TopicSession // Create a durable topic subscriber String subscriptionName;TopicSubscriber subscriber = session.createDurableSubscriber(topic,subscriptionName); The TopicSubscriber can then be used to receive messages just like any other TopicSubscriber. When the client is ready to terminate the session, it can close down the subscriber, session, and connection in the conventional way. All messages previously published to the topic are stored by the JMS provider. // We've finished with the durable subscription for the last time
session.unsubscribe(subscriptionName);
This method uses the given subscriptionName and the clientID of the connection to designate the subscription for cancellation. |
Wiki Content Tree
Your Feedback Needed!
We need your help to improve this wiki site. If you have any suggestions or corrections, write to us at techw@gigaspaces.com. Please provide a link to the wiki page you are referring to.
Add Comment