Nov 30th, 2010, 05:04 PM
Receiving Messages based on a Message Selector
I am using Spring AMPQ and I would like to do the following.
I want to implement the request response pattern using the correlation Id with 2 durable queues (request queue and a response queue) bound to one exchange.
I am using the MessagePostProcessor to set the Correlation Id on the message when sending the message to the exchange along with the reply to address.
I want to receive the message on the same thread synchronously using the AMPQ template using a message selector (I want to use the correlation Id i setup as the message selector to filter messages). I don't see the message selector option on the AMPQ template. The AMPQ Spec reads that this functionality is available. Is this implemented yet? If yes how do i specify a selector when receiving a message?
I am specifically interested in knowing how the message selector works and how to configure it. I have a work around for this problem but i would prefer to do it using a message selector.
Thanks in advance for the help.
Dec 3rd, 2010, 10:48 AM
Is this possible with the current release of Spring AMPQ? Would like to know how to go about this.
Appreciate any response.
Dec 8th, 2010, 02:06 AM
Which spec were you reading? I found a passing reference to message selectors in 0.9.1, but no indication that they should be implemented by a provider.
Request-response (or RPC) is a common pattern with AMQP, but it's not efficient to do it with 2 fixed queues (in any messaging system that I know of). The easiest way to implement RPC with AMQP is to use an anonymous queue for the response and a plain direct exchange (even the default exchange). This pattern is implemented in a convenience method in RabbitTemplate.
Dec 9th, 2010, 10:44 AM
Thanks for the reply. I wanted to use 2 durable request and request queues. I don't want to loose the response if my handlers go down for some reason. Can the anonymous queue be setup as a durable queue? I will plan to use the anonymous queues for this purpose.
Also is there any capability of a message selector? I read this on 0.8 spec. I see this is no longer there on 1.0 spec. It talks about message filters instead.
Thanks for the reply. If you know anything about message filters please let me know.
Dec 9th, 2010, 11:20 AM
Anonymous queues are non-durable and exclusive (a bit like temporary queues in JMS). If you a need durable response with the same features you would need to do something different. One option would be to create a queue per consumer using some algorithm to generate the queue name that you know is unique but repeatable (the same algorithm could be used to create the message selector in your original design). Then your consumers know they are unique.
Dec 9th, 2010, 12:09 PM