根据相应的 JMS ID 选择消息的正确语法是什么?
目前我使用:
String selector = "JMSMessageID='ID:305:1:5:1:1'";
messageConsumer = session.createConsumer(getRetryQueue(), selector);
上述语法在模拟代理的测试中有效。但是对于 ActiveMQ,消息不会被轮询。
原始代码:
@Override
public Message readMessageFromRetryQueueByJmsId(String jmsId) throws QueueingException {
Connection connection = null;
Session session = null;
MessageConsumer messageConsumer = null;
Message message = null;
try {
connection = getConnectionFactory().createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
messageConsumer = session.createConsumer(getRetryQueue(), "JMSMessageID='"+jmsId+"'");
message = messageConsumer.receiveNoWait();
} catch (JMSException e) {
throw new QueueingException("Failed to read message from MessageConsumer.");
} finally {
try { messageConsumer.close(); } catch (Exception e) { /* NOP */ }
try { session.close(); } catch (Exception e) { /* NOP */ }
try { connection.close(); } catch (Exception e) { /* NOP */ }
}
return message;
}