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 Creating 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 namedmySub1
.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.
durableTopicSubscriber
is run to create a durable topic subscriber.- 5 messages are sent to theÂ
myTopic
 topic. The messages will be received and printed by the subscriber namedÂdurableTopicSubscriber
. - TheÂ
durableTopicSubscriber
is stopped. - The publisher is run again and 5 more messages are sent.
- 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
.