Arun
Arun

Reputation: 1088

Apache camel - How to use activemq Selective consumer using message body

I want two consumer with single activemq queue and wanted to filter while consuming. Selective is best option for me (please suggest if there is other). But sender does not sending me any header parameter or any property, selective only works with header or properties, now I wanted to filter message on message body . Is there any way to use selective with message body

My two messages body are differed by test and test2

{
   "test":{
      "abc":"123",
      "cde":"123"     
   }
}





{
   "test2":{
     "abc":"321",
     "cde":"321"
   }
}

I want something like selective with message body

from("jms:selective?selector=" + java.net.URLEncoder.encode(${body.test})).
    to("cxf:bean:replica01");

from("jms:selective?selector=" + java.net.URLEncoder.encode(${body.test2})).
    to("cxf:bean:replica02");

Please suggest if there is any way to do so.

Upvotes: 0

Views: 884

Answers (1)

Justin Bertram
Justin Bertram

Reputation: 35008

As the selector documentation for ActiveMQ 5.x points out, you can use XPath based selectors for messages which have XML bodies. However, the bodies of your messages aren't XML so there doesn't appear to be anyway to get the functionality you're looking for.

Keep in mind that as far as the broker is concerned the body of a message is just an array of bytes whereas message headers/properties are typed which allows for the kinds of comparison operations that make selectors viable.

Upvotes: 1

Related Questions