This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Creating a Durable Topic Subscription

Durable topics keep messages persistently until a suitable consumer is available to consume them. Durable topic subscribers are used when an application needs to receive messages that are published even while the application is inactive. See Managing Durable Topic Subscriptions for more information.

About the sample

The <MB_HOME>/Samples/DurableTopicSubscriber/src/org/sample/jms directory has the following classes.

  • DurableTopicSubscriber.java class creates a durable topic subscription named mySub1.

  • SampleMessageListener.java class creates a consumer for the durable topic subscription. 

  • TopicPublisher.java class creates a publisher to publish messages in the durable topic. 

  • Main.java defines the method for calling the three clients mentioned above. 

Click the relevant tab to see the code.

Prerequisites

See Prerequisites to Run the MB Samples for a list of prerequisites.

Executing the sample

Run the ant command from the <MB_Home>/samples/DurableTopicSubscriber directory.

Analyzing the output

The scenario used in this sample to demonstrate durable topic subscriptions is as follows.

  1. durableTopicSubscriber is run to create a durable topic subscriber.
  2. 5 messages are sent to the myTopic topic. The messages will be received and printed by the subscriber named durableTopicSubscriber.
  3. The durableTopicSubscriber is stopped.
  4. The publisher is run again and 5 more messages are sent.
  5. While running durableTopicSubscriber again, 5 different messages are sent to the same topic. You will see that all 10 messages (including the messages sent to the topic when the subscriber was absent) are consumed by the durableTopicSubscriber.