how to read only specific queue messages based on message header property

北城以北 提交于 2019-12-12 14:04:27

问题


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.?

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);

回答1:


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.

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")..



来源:https://stackoverflow.com/questions/31549200/how-to-read-only-specific-queue-messages-based-on-message-header-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!