Got a problem with selecting message from topic by message id. Here’s the boiled down code:
//publish message
connectionFactory = new ActiveMQConnectionFactory("vm://localhost");
//or external broker: tcp://localhost:61616
con = connectionFactory.createConnection();
con.setClientID("foo");
con.start();
session = connection.createSession(true, Session.SESSION_TRANSACTED);
topic = session.createTopic("topic_name");
producer = session.createProducer(topic);
//create text message
producer.send(message);
messageId = message.getJMSMessageID();
session.commit();
//close all stuff
//get message by id (the same VM split second after publishing)
//get connection the same way as for publishing
session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
topic = session.createTopic("topic_name");
consumer = session.createDurableSubscriber(topic, "SUBS1", "JMSMessageID='messageId'", false);
//here we get stuck though the message IS there
msg = consumer.receive(); //receiveNoWait gives null
moreover even if I provide selector which is always true e.g. "1=1" or empty one : "", null
it does not fetch messages too despite it is durable subscriber.
On the other hand if I post something after consumer with alsways true selector was created it does fetch this message.
but code like this DOES fetch all my messages including the one with id i've been looking for
consumer = session.createDurableSubscriber(topic, "SUBS1");
while (msg != null) {
msg = consumer.receive();
}
It looks to me that DurableSubscriber with selector ignores existing messages. Though I didn't find anything like that in the jms 1.1 spec
So far I tried only ActiveMQ 5.5.1 as JMS provider
The question is am I doing something wrong or it is a bug?