Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use filters dynamically ? #406

Open
suryalokhande opened this issue May 2, 2023 · 12 comments
Open

How to use filters dynamically ? #406

suryalokhande opened this issue May 2, 2023 · 12 comments

Comments

@suryalokhande
Copy link

Hello Team,

We are using the rhea client to monitor topic say "data".
and am using filters
var receiver_opts = {
source: {
filter:filter.selector("x=100'") //-- Filter is applied on application_properties’s attributes
}
}
connection.open_receiver(receiver_opts);

My Question is :

  1. Can see that filter works only with attributes of application_properties ? correct me.
    from this example : https://github.com/amqp/rhea/blob/bc63ef3527a42167822a2507574eaa1bc5e57958/examples/selector/send.js

  2. is there way to configure filters dynamically ? say initially, when i start my application, i want to filter X data
    then user is also interested in Y data and Z data.. so on so for.
    how to configure filters dynamically on open_receiver method ? do i need to create every time open_receiver object ?

@grs
Copy link
Member

grs commented May 2, 2023

The filters are actually handled by the broker. The client merely passes them through. The specification allows for use of other message properties as well as application properties. The filter can only be set on opening a receiver. If you need to change it you will need to close the original receiver and create a new one.

@suryalokhande suryalokhande changed the title How to user filters dynamically ? How to use filters dynamically ? May 2, 2023
@suryalokhande
Copy link
Author

Thank you grs for guiding me on this line.

@suryalokhande
Copy link
Author

One more question, How to pass multiple filters ? to selector function any sample snippet ?

@grs
Copy link
Member

grs commented May 4, 2023

Whether a broker supports multiple filters on the same link will be a question for the particular broker. However the selector can combine multiple terms, so that may be sufficient.

As to the mechanism in the client, you just need to pass a map as the value for filters and that can contain multiple entries if supported by the broker.

@suryalokhande
Copy link
Author

Thank grs for your quick turnaround.
Yes in my case broker support multiple filters,

have spent some time to configure filters from map way
let me set context...

  1. filter set by inline case
    here am interested in to process messages that has cluster_version with value '9.13.0' in application_properties
    filter:filter.selector("cluster_version='9.13.0'")
    i.e message as below
    Message {
    ---
    application_properties: {
    -----
    cluster_version: '9.13.0'
    },
    }

    Can see the my sample application recieves message, as it has cluster_version: '9.13.0 in it and filter is working fine.

  2. filter set by map case,
    am setting 'cluster_version' value as 9.13.1 as below...

const filtersMap = {};
here, now am interested in to process messages only that has cluster_version with value 9.13.1
filtersMap['cluster_version']='9.13.1';
filter:filter.selector(filtersMap)

now, am passing message that has cluster_version value as 9.13.0 to my topic.
my sample application still receives this message, even cluster_version value as 9.13.0

am expecting
my application should be not receive messages, when cluster_version value is 9.13.0
as have configured from filters am interested in 9.13.1 only, why my application received message for 9.13.0 ?

my questions,

  1. Am i missing something when used with Map route ?
  2. How to configure multiple filters from map to make it work ?

@grs
Copy link
Member

grs commented May 4, 2023

The return value of filters.selector() is a map. You can add other filters into that map (as long as they are correctly formatted according o the specification of the filter. Obviously you can't set multiple different selector filters on the same receiver, though the single selector can have multiple terms.

@suryalokhande
Copy link
Author

Thank you grs,

if my message from amqp topic, which am listening to.

Message {
durable: false,
priority: 4,
first_acquirer: true,
to: 'data',
creation_time: 2023-05-04T22:03:24.478Z,
application_properties: {
cluster_uuid: '31baa6b7-e479',
cluster_version: '9.13.0'
},
body: "{Hello}"
}

either this works
filter:filter.selector("cluster_version='9.13.0'"),
or
filter:filter.selector("cluster_uuid='31baa6b7-e479'"),

but if when use
filter:filter.selector("first_acquirer='true'"), <-- does not as it's attribute of message not member of application_properties's attributes.

but when i used selector values with comma or space separated fails...
filter:filters.selector("cluster_version='9.13.0' , volume_name='A'") // Comma separated
or
filter:filters.selector("cluster_version='9.13.0' x='10'") // Space separated

Two use case not able make it work, is

  1. Multiple filters with single selector function only.
  2. not able to filter non application_properties filters.

any inputs for multiple filters and non application_properties filters

@grs
Copy link
Member

grs commented May 5, 2023

For message properties, you need to prefix them with amqp.. I am not sure if amqp.first_acquirer will be recognised (amqp.delivery_count > 0 might be an alternative check if not. The details of the filter are defined here: https://svn.apache.org/repos/asf/qpid/trunk/qpid/specs/apache-filters.xml#type-selector-filter though that mostly delegates to the specification of JMS selectors.

To combine terms, use AND e.g. "cluster_version='9.13.0' AND volume_name='A'"

@suryalokhande
Copy link
Author

let me try appending amqp then will update you.

@suryalokhande
Copy link
Author

using filter like amqp.first_acquirer is not helping us.

@grs
Copy link
Member

grs commented May 19, 2023

I would suggest asking the support for the broker you are using what they recommend for your use case.

@suryalokhande
Copy link
Author

sure, let me reach up with my backend team and collect data on broker side. thanks a lot for your support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants