Skip to content

Support 'selector' header for subscriptions with SimpleBrokerMessageHandler [SPR-12884] #17482

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

Closed
spring-projects-issues opened this issue Apr 2, 2015 · 9 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Apr 2, 2015

Christopher Shannon opened SPR-12884 and commented

I am currently using STOMP over Websockets and the Simple message broker to publish messages to clients. In my case, the simple message broker support works great, except the one feature that is missing that would be really useful is message selector support to filter out certain messages sent to clients. I could use a full featured message broker for this feature but a full broker is a bit overkill for what I need.

I suggest adding message selector support to the Simple message broker (or to another internal broker in spring). Instead of having to write custom logic to filter messages, it would be nice to be able to register a selector in a header to filter out messages dynamically.

Adding support for a JMS message selector expression (which is based on a subset of SQL92 conditional syntax) would be great but would probably be difficult and might best suited to leave for a full featured broker.

Something else that might work instead would be to use a syntax based on the Spring Expression Language if there is a good way to implement this in a generic way. This should be a lot more straight forward since SpEL is used elsewhere all over the framework.

Even if SpEL wouldn't work really work, just having basic filtering support on headers by using a syntax such as "someProperty = 'true'" or "someProperty > 10" would be useful.


Affects: 4.1.6

Issue Links:

Referenced from: commits 0b43e4e, b6327ac

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

The SimpleBrokerMessageHandler filters based on destination prefixes, which comes from the base class AbstractBrokerMessageHandler. Since the SimpleBrokerMessageHandler and the DefaultSubscriptionRegistry use PathMatcher for matching destinations, we could add a destionationPatterns property in SimpleBrokerMessageHandler that would be used in addition to the destination prefixes from the base class.

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

We'll give this a try for 4.2.

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

Actually based on another comment you made I'm not sure I fully understood what you meant. I thought that you want to filter all messages coming into the handleMessage method. It sounds more like you want to filter in the sendMessageToSubscribers method, i.e. whether a subscriber should get a specific message or not. Could you elaborate a little pleaes?

@spring-projects-issues
Copy link
Collaborator Author

Christopher Shannon commented

This would apply more for the sendMessageToSubscribers. My other comment was related in that it would be nice to be able to get access to the headers to access a custom property on a subscription that could be used for deciding which subscribers to send the message to.

For this ticket, I thought it might be useful to add the ability to build that behavior into the actual framework generically. So for example, a client might subscribe to a specific destination. But instead of receiving all messages, the client could specify they only want to receive messages based on a property in a header. So maybe they only want to receive messages that contain "age > 100".

This behavior is a standard part of JMS and is described here: http://docs.oracle.com/cd/E19798-01/821-1841/bncer/index.html

Obviously, this is not JMS, but it would be nice to have a similar feature in that a client could filter out what it receives based on the content of a message. Does that make sense?

@spring-projects-issues
Copy link
Collaborator Author

Christopher Shannon commented

For more clarification, here is how ActiveMQ Apollo supports message selectors over STOMP.

https://activemq.apache.org/apollo/documentation/stomp-manual.html#Message_Selectors

You specify a selector as a header. This is why in the other comment I made I wanted to be able to access the headers for a subscription to add in custom filtering logic.

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

Okay thanks. I'll try SpEL expressions and see what that looks like.

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

Christopher Shannon I've added SpEL based selector header support. I think that will work out fine but if you could give it a try, that'd be great. See commit b6327a.

@spring-projects-issues
Copy link
Collaborator Author

Christopher Shannon commented

Thanks for getting that into the build. I will pull down the latest Snapshot and take a look at it sometime in the next few days to play with some test cases but at first glance it looks good.

@spring-projects-issues
Copy link
Collaborator Author

Pavel Muravyov commented

Hi everyone,

I have just found this Jira request which helped me to finally configure selector on the client. But it takes several hours to make it work. For simple custom message header 'person' of type Long this should be placed as a selector:

selector: "headers['nativeHeaders']['person'][0] == '129'"

Not really straightforward. Is there a more simple way for the same result?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants