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.javaclass creates a durable topic subscription namedmySub1.SampleMessageListener.javaclass creates a consumer for the durable topic subscription.TopicPublisher.javaclass creates a publisher to publish messages in the durable topic.Main.javadefines 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.
durableTopicSubscriberis run to create a durable topic subscriber.- 5 messages are sent to the
myTopictopic. The messages will be received and printed by the subscriber nameddurableTopicSubscriber. - The
durableTopicSubscriberis stopped. - The publisher is run again and 5 more messages are sent.
- While running
durableTopicSubscriberagain, 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 thedurableTopicSubscriber.