我正在使用Stringboot,springboot starter artemis和camel
这是我对他们的依赖:
compile('org.springframework.boot:spring-boot-starter-artemis')
compile 'org.springframework:spring-jms'
compile 'org.apache.activemq:artemis-jms-client:1.5.6'
compile 'org.apache.activemq:artemis-jms-server:1.5.6'
// https://mvnrepository.com/artifact/org.apache.camel/camel-jms
compile group: 'org.apache.camel', name: 'camel-jms', version: '2.20.2'
这是我的代码(由于某些原因,我在这里没有使用jms模板)
Connection connection = connectionFactory.createConnection();
try {
connection.setClientID(clientId);
connection.start();
//Create a JMS session
Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
Topic topic = ActiveMQJMSClient.createTopic(processedHeaders.get(jmsdestination));
******JmsMessageUUID will dynamic, i have added JmsMessageUUID value = ID:142536687 as a example*********
String selector = "JmsMessageUUID = 'ID:142536687'";
//Create the subscription and the subscriber.
MessageConsumer subscriber = session.createConsumer(topic,selector);
//Consume the message from the durable subscription
TextMessage messageReceived = (TextMessage) subscriber.receive();
System.out.println("Received message: " + messageReceived.getText());
// Acknowledge message
messageReceived.acknowledge();
} finally {
if (connection != null) {
// Close our JMS resources!
connection.close();
} }
}
我试图用JmsMessageUUID选择消息,它基本上是一个在发送消息期间设置的随机字符串,Jms选择器无法找到消息,但是当我没有使用选择器而不是成功消费消息我也检查了收到的消息中的jms属性,并且JmsMessageUUID在具有相同字符串值的属性中可用。
我无法弄清楚选择器无效的原因?请帮帮我..
我还发现 JMSMessageID 过滤器使用队列,但没有使用Topoc :(