1

I have a very simple ActiveMQ message consumer that's created in C# as follows:

using(IMessageConsumer consumer = session.CreateConsumer(destination,"NMSCorrelationID='<value of correlation id>'")){

   /* This Receive(..) operation does not retrieve the message with the correlation id which I confirmed to be available on the queue. */
   IMessage message = consumer.Receive(new TimeSpan(1000));

}

However, I can get the message if I don't use the selector while creating the consumer. The destination is a queue on the ActiveMQ broker. I've tried using CorrelationID and JMSCorrelationID as the selectors, but none on them worked. The ActiveMQ broker was installed with out-of-the-box settings. Is there any special setting that I need to use for the selectors to work?

Shad
  • 4,423
  • 3
  • 36
  • 37
naveen
  • 219
  • 4
  • 12

1 Answers1

3

You definitely want to set the selector with JMSCorrelationID. Using NMSCorrelationID, or just CorrelationID will cause it to ignore all of the messages. I tested the following out with both topics and queues, and everything worked correctly. I did test on ActiveMQ 5.8.0, but I'm pretty sure this will work just fine on 5.7.0.

IMessageConsumer subscriber = session.CreateConsumer(
                                 "queue://TestCorrelation",
                                 "JMSCorrelationID = 'FOO'",
                                 false);

The broker will not enqueue a message to a consumer from the same connection as the producer if that consumer has set the third parameter (noLocal) to true. You will need to have two separate connections to get the correlation ID selector to work. One to send the message, a consumer on another connection to receive the message. If you set noLocal to false, then a consumer on the same connection as the producer will receive the message.

You can also try using some wildcards in the selector if you want to test.

"JMSCorrelationID LIKE '%FOO%'"

Be aware that the selector is case sensitive. Your correlation IDs must match exactly.

Jim Gomes
  • 774
  • 8
  • 15
  • Gomez: Is there documentation on this wildcards? – Meysam Javadi Dec 30 '13 at 07:13
  • 1
    Meysam - they are the standard JMS selector wildcards. Here's a link that should get you started, but I'm sure there are probably better resources. http://docs.oracle.com/javaee/1.4/api/javax/jms/Message.html – Jim Gomes Jan 28 '14 at 01:26