Creating a Durable Subscriber
As described in Publish and Subscribe, subscribers, by default, only receive messages when they are active. If messages are published when the subscriber is not available, the subscriber does not receive those messages. You can create durable subscriptions, where subscriptions are stored on the server and subscribers can receive messages even if it was inactive when the message was originally delivered.
In this example, you create a durable subscriber that stores messages published to topic
myTopic on the EMS server.
To start
user2 as a durable subscriber:
- Procedure
- In the a command line window, navigate to the
EMS_HOME/samples/javafolder. - Enter setup to set the environment and classpath:
> setup - Execute the
tibjmsDurableapplication to assignuser2as a durable subscriber to themyTopictopic:> java tibjmsDurable -topic myTopic -user user2 - In the administration tool, use the
show durables command to confirm that
user2is a durable subscriber tomyTopic:tcp://localhost:7222> show durables
Topic Name Durable User Msgs Size
* myTopic subscriber user2 0 0.0 Kb - In the subscriber window, enter Ctrl+C to stop the subscriber.
- In another command line window, execute the
tibjmsMsgProducerclient, as described in Starting the Publisher Client and Sending Messages:> java tibjmsMsgProducer -topic myTopic -user user1 hello user2 - Restart the subscriber:
> java tibjmsDurable -topic myTopic -user user2The stored messages are displayed in the subscriber window.
- Enter Ctrl+C to stop the subscriber and then unsubscribe the durable subscription:
> java tibjmsDurable -unsubscribeThe subscriber is no longer durable and any additional messages published to the
myTopictopic are lost.