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

  1. In the a command line window, navigate to the EMS_HOME/samples/java folder.
  2. Enter setup to set the environment and classpath:
    > setup
  3. Execute the tibjmsDurable application to assign user2 as a durable subscriber to the myTopic topic:
    > java tibjmsDurable -topic myTopic -user user2
  4. In the administration tool, use the show durables command to confirm that user2 is a durable subscriber to myTopic:
    tcp://localhost:7222> show durables
   Topic Name     Durable      User    Msgs     Size
 * myTopic       subscriber   user2   0       0.0 Kb
  5. In the subscriber window, enter Ctrl+C to stop the subscriber.
  6. 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
  7. Restart the subscriber:
    > java tibjmsDurable -topic myTopic -user user2

    The stored messages are displayed in the subscriber window.

  8. 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.