通过消息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