minghuaw / fe2o3-amqp

A rust implementation of the AMQP1.0 protocol based on serde and tokio.
MIT License
58 stars 7 forks source link

Equivalency to JSM selector #202

Closed VLorz closed 1 year ago

VLorz commented 1 year ago

I need to receive messages from a broker on a topic using a selector. Available sample code is in Java and uses a JMS Message Selector, using an annotation similar to this:

    @JmsListener(destination = "my.topic", containerFactory = "myFactory", selector = 
        "((DEVICECLASS IS NULL) AND (DEVICEID=123456)) OR " +
        "((DEVICEID=123456) AND (DEVICECLASS='SOMETHING')) OR " +
        "((DEVICEID IS NULL) AND (DEVICECLASS IS NULL)) OR " +
        "((DEVICEID IS NULL) AND (DEVICECLASS='SOMETHING'))"
    )

DEVICECLASS and DEVICEID are message properties set by the message sender. The sample code receive with filter sets a selector filter, but uses a key which is a bit confusing for me, as it has same property name as used in the filter.

    let source = Source::builder()
        .address("q1")
        .add_to_filter("sn", SelectorFilter(String::from("sn = 100")))
        .build();

What is the equivalent form in fe2o3 library for specifying the selector filter like in previous JMS example? Thanks a lot in advance.

minghuaw commented 1 year ago

Hi @VLorz

The key shouldn't matter. You should be able to use any string value for your key. I was just being lazy when I coded that example. More details on translating JMS selector filter to AMQP 1.0 selector filter can be found on this doc (https://svn.apache.org/repos/asf/qpid/trunk/qpid/specs/apache-filters.xml#type-selector-filter).

Feel free to let me know if this helps :)

VLorz commented 1 year ago

Hi @minghuaw, it worked against an ActiveMQ 5.16.3 using "selector" as key. I think it was not working previously due to an invalid character I seem to have introduced in the selector query. Thanks a lot once again!