如何根据消息头属性仅读取特定队列消息 [英] how to read only specific queue messages based on message header property
问题描述
我在 activemq 队列中有一个消息列表.每条消息都有一个带有值的自定义标头属性.我应该如何才能仅访问自定义标头属性值 = 123 的那些消息.?
I have a list of messages in activemq queue. each message has a custom header property with value. How I should be able to access only those messages whose custom header property value = 123.?
我正在使用类似下面的东西从队列中选择一条消息.如何选择具有 customHeaderProperty =123 的所有消息或单个消息.?
I am using something like below to pick a message from queue. How to pick all messages which or a single message which has customHeaderProperty =123.?
ConsumerTemplate consumerTemplate = camelContext.createConsumerTemplate();
Exchange ex = consumerTemplate.receive("activemq:queueName",10000);
String data = ex.getIn().getBody(String.class);
String number = ex.getIn().getHeader("customProperty", String.class);
推荐答案
在消费者上使用消息选择器.选择器是类似于 SQL 的查询.所以你可以写一些类似 myCustomHeader = 123
的东西.这是一个非常好的备忘单.
Use message selectors on the consumer. A selector is a SQL like query. So you could write something like myCustomHeader = 123
. Here is a pretty good cheat sheet.
由于您使用 apache-camel 标记了问题,我猜您正在使用 Camel 设置.在这种情况下,您需要为 Camel 提供选择器.类似于 from("activemq:queue:myqueue?selector=myCustomHeader%3D123").
.
Since you tagged the question with apache-camel, I guess you are working with a Camel setup. In that case, you need to supply the selector to Camel. Something like from("activemq:queue:myqueue?selector=myCustomHeader%3D123").
.
这篇关于如何根据消息头属性仅读取特定队列消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!