This example is almost the same as here activemq-jms-first-touch
and base on it we can learn something new, and it is difference between Durable and Nondurable Subscriber.
To test how Nondurable Subscriber works, simpli check this example activemq-jms-first-touch.
Test scenario 1:
This is how Nondurable Subscriber works.
To switch Subscriber to *Durable *mode you have to:
set client id for connection (TopicConnection)
... topicConnection.setClientID("1"); ...
and instead of creating subscriberSession.createSubscriber use subscriberSession.createDurableSubscriber
... TopicSubscriber subscriber = subscriberSession.createDurableSubscriber(chatTopic, "Subscriber1"); ...
Test scenario 2:
As you see the main difference is that Durable subscriber has Cache functionality that store messages for Subscriber when it is not active.