Consumer with message selector not working

329 Views Asked by At

I have a simple consumer:

            try
            {
                factory = new NMSConnectionFactory(Settings.Endpoint);

                connection = factory.CreateConnection(Settings.UserName, Settings.Password);
                connection.ClientId = Settings.Name;

                session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
                destination = SessionUtil.GetDestination(session, Settings.QueueName, DestinationType.Queue);

                consumer = session.CreateConsumer(destination, "portCode = 'GB'", false);

                consumer.Listener += new MessageListener(OnMessage);         
            }
            catch
            {
                throw;
            }

I need to apply a selector to get messages when the portCode field is equal to "GB". This queue receives many messages.

The message is in JSON and a sample of this message is shown below:

{
  "message": {
    "list": [
      {
    xxxxxxx
      }
    ]
  },
  "header": {
    "messageCode": "xxxxxx",
    "portCode": "GB",
    "sourceSystem": "origin",
    "messageId": "ca0bf0e0-cefa-4f5a-a80a-b518e7d2f645",
    "dateTimeMessage": "2021-04-22T07:12:48.000-0300",
    "version": "1.0"
  }
}

However, I do not receive messages using the specified "GB" selector. It seems simple to define selectors, but it is not working for me.

Thanks.

1

There are 1 best solutions below

0
On BEST ANSWER

Selectors do not work on the body of the message (i.e. your JSON data). They only work on the headers and properties of the message.