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/java
folder. - Enter setup to set the environment and classpath:
> setup
- Execute the
tibjmsDurable
application to assignuser2
as a durable subscriber to themyTopic
topic:> java tibjmsDurable -topic myTopic -user user2
- In the administration tool, use the
show durables command to confirm that
user2
is 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
tibjmsMsgProducer
client, 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 user2
The stored messages are displayed in the subscriber window.
- Enter Ctrl+C to stop the subscriber and then unsubscribe the durable subscription:
> java tibjmsDurable -unsubscribe
The subscriber is no longer durable and any additional messages published to the
myTopic
topic are lost.