activemq-classicnms

ActiveMQ(NMS) : Is there a way to run a query on the queue to find out all messages with certain header values?


I am using ActiveMQ to store messages to be used later. It is working as expected, but there is a specific scenario I need to fit which I cannot figure out. The short question is this.

Is there a way to run a query on the queue to find out all messages with certain header values?

The problem in detail is this :

So there is a set of data that is coming in multiple messages and the requirement is to use that data only after all messages for that has come in. So if the dataset has lets say 50 messages i need to wait for those 50 messages and then read them in. I am adding headers to each message to denote they belong to a certain set. Like "TotalSets"=50 , "SetId"=39 . I would like to write a thread that keeps tracing if all sets for a particular batch has arrived.


Solution

  • NMS is a .NET equivalent to the JMS messaging API so the means of filtering messages is the same as in JMS, your subscription applies a JMS Message Selector when created to tell the broker what messages it is interested in. The session methods to create MessageConsumer instances have variants that accept the selector using the JMS defined syntax which is your means of filtering messages.