I have a dynamic topic tree on which the last message for each topic is "retained". When I subscribe to the topic tree (with JMS/Java/MQLibs), as it's dynamic and I am subscribing with the wildcard character "#", I cannot know what topics I will receive in advance. So,
How can I know when I have read all available topics at least once?
How can I know that the read topic is the original "retained" message that existed before I subscribed or is an update after subscription? (Do I need to keep a local map of MessageIDs against topics? I assume I cannot compare the time stamp of when I subscribed with the message creation time as the clock on the server and client may differ).
I have added some sample code, to show that I am accessing Topics not Queues.
public class JMSServerSubscriber implements MessageListener {
public JMSServerSubscriber() throws JMSException {
TopicConnection topicCon = JmsTopicConnectionFactory.createTopicConnection();
TopicSession topicSes = topicCon.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = topicSes.createTopic("#");
TopicSubscriber topicSub = topicSes.createSubscriber(topic);
topicSub.setMessageListener(this);
topicCon.start();
}
@Override
public void onMessage(Message arg0) {
BytesMessage bm = (BytesMessage) arg0;
try {
String destination = bm.getJMSDestination().toString();
} catch (JMSException e) {
e.printStackTrace();
}
}
}
/BusRoute/1
/BusRoute/2
, and I subscribe to/BusRoute/#
. I will get an immediate response for1
and2
, but how would I know that that is all there is? – lafual