Filters on messages don't work fine


adding the filters feature is a great value but the test method for it is so simple.
I have modified it in the following way ...
Connection connection = new Connection(address);
            Session session = new Session(connection);

            SenderLink sender = new SenderLink(session, "send-link", "q1");

            for (int i = 0; i < 10; i++)
                Message message = new Message("I can match a filter");
                message.Properties = new Properties() { GroupId = "abcdefg" };
                message.ApplicationProperties = new ApplicationProperties();
                message.ApplicationProperties["sn"] = i;
                sender.Send(message, null, null);

            // update the filter descriptor and expression according to the broker
            Map filters = new Map();
            filters.Add(new Symbol("f1"), new DescribedValue(new Descriptor(0x0000468C00000004L, "apache.org:selector-filter:string")) { Value = "sn == 5" });
            ReceiverLink receiver = new ReceiverLink(session, "receive-link", new Source() { Address = "q1", FilterSet = filters });

            for (int i = 0; i < 10; ++i)
                Message message2 = receiver.Receive();
                Trace.WriteLine(TraceLevel.Information, "receive: {0}", message2.ApplicationProperties["sn"]);

The sender send 10 messages with sn = i but the receiver set a filter to receive only one message with sn = 5. The filter seems to not work because the receiver can receive all 10 messages.

There is a problem in my code ... or a bug on filter feature ?

Closed Sep 1, 2015 at 1:15 AM by xinchen


xinchen wrote Jun 13, 2014 at 6:34 PM

AMQP does not define a standard syntax for filter expressions. The value (described type) is also broker specific. The sample was kept simple to only illustrates how to create a receiver with a filter on messages. Without knowing the broker specific requirements, the filter descriptor or the expression may not be understood by the broker.

Which broker did you use to run the test? If it was the Service Bus, it is expected to receive all messages because the SB uses a different model for pub/sub (subscriptions are created with filters on a topic through management APIs and receiver performs receives from the subscriptions without filters). An JMS broker may understand the selector filter but I am not sure if the expression ("sn == 5") is valid or not.

ppatierno wrote Jun 13, 2014 at 7:48 PM

Ok ... You were very clear ... It was my fault !
I'm using Service Bus.
I will try with ActiveMQ or Qpid Proton broker.
Sorry for the opened issue.


ppatierno wrote Jun 15, 2014 at 12:56 PM

I used ActiveMQ that uses JMS style selectors (filters) and the correct way for my example filter is the following :

filters.Add(new Symbol("jms-selector"), new DescribedValue(new Descriptor(0x0000468C00000004L, "apache.org:selector-filter:string")) { Value = "sn = 5" });

"jms-selector" as name of filter and "sn = 5" as SQL syntax expression.

It works like a charm !


xinchen wrote Jun 15, 2014 at 9:14 PM

Thanks for verifying that the JMS selector filter works!