通過消息ID從主題中選擇消息時出現問題。 這裏的歸結代碼:JMS:無法通過選擇器從主題中選擇jms消息
//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
而且即使我提供選擇這始終是真正的 例如「1 = 1」或空的:「」,null
即使它是持久訂閱者,它也不會獲取消息。
另一方面,如果我在消費者之後發佈了一些東西,並且創建了真選擇器,它確實會獲取此消息。
,但像這樣的代碼並獲取我的所有消息,包括一個用ID我一直在尋找
consumer = session.createDurableSubscriber(topic, "SUBS1");
while (msg != null) {
msg = consumer.receive();
}
它看起來對我說DurableSubscriber與選擇忽略現有消息。雖然我沒有找到像在JMS 1.1規範
到目前爲止,我只試過5.5.1的ActiveMQ作爲JMS提供任何
問題是我做錯了什麼,或者它是一個錯誤嗎?
thanx。現在它很清楚它是如何工作的 – 2012-01-06 08:54:05