JMS Durable Subscriptions

  GigaSpaces 5.X

Documentation Home
Quick Start Guide
Release Notes

Previous release

  Search Here
Searching GigaSpaces Platform 5.X Documentation

                                               

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.

Overview

A 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.
The concept behind a durable subscription is that whenever the subscriber is not running, messages that it would likely receive are stored by the JMS provider. After the subscriber is restarted, the stored messages are delivered.
To define a durable subscription, a subscription name and client ID are required. After the subscriber is restarted, you must use that same subscription name and client ID to retrieve the messages.

  • Subscription name – a string specified by the client.
  • Client ID – an attribute of the JMS connection; specified using the method setClientID() of the JMS Connection.

Only one session at a time can have a TopicSubscriber for a particular durable subscription.

To create durable subscriptions, you may first have to configure the space durable subscriber worker. For more details, see the JMS Space Configuration section.

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.
After the client restarts, it will create a connection using the previously specified clientID, as well as create a durable TopicSubscriber using the previously specified name. The JMS provider then delivers all messages that were published to the topic while the client was inactive.
When the client no longer requires the durable subscription, it must end it using the unsubscribe() method, as demonstrated below:

// 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.

Labels

 
(None)