Marcin Michalski
Marcin Michalski

Reputation: 1266

JMS Message Selector implementation

I need to verify whether javax.jms.Message matches provided selector i.e.:

Message msg = ...;
SomeSelectorMatcher matcher = new SomeSelectorMatcher(" someProp='someVal' and someProp2 >3 ... ");

if(matcher.matches(msg){
     //do sth
}else{
     //do sth else
}

Is there any out of the box library which does that ?

Upvotes: 1

Views: 3427

Answers (2)

Marcin Michalski
Marcin Michalski

Reputation: 1266

I needed to implement simple test framework which would simulate JMS behaviour but using synchronous approach. Anyway I was able to find library which has Message Selector parser implemented - http://openjms.sourceforge.net/

Upvotes: 1

lzap
lzap

Reputation: 17173

Message selectors are not meant do allow this. Why you whould need this?

I'd recommend to create multiple consumers for it. E.g. from your example above I would create two consumers. One with this code:

//do sth

and the second for

//do sth else

The first would have the selector and the second the selector logically opposite.

If you really need to do filtering after you receive the message you can directly compare your headers and properties from the incoming message. You can even process the body while selectors cannot do that.

http://download.oracle.com/javaee/5/tutorial/doc/bnceh.html

Upvotes: 0

Related Questions