Reputation: 479
I need to send and receive an ack synchronously and for that I am using the RabbitTemplate.
The RabbitTemplate has queue and replyAddress property, but when trying to send me this error appears:
java.lang.IllegalStateException: RabbitTemplate is not configured as MessageListener - can not use a 'replyAddress': amq.gen-t1ESvGc4I8EfGJCjWjBxKw
If I use the Send method instead of SendAndReceive then the process is correct but the response arrives asynchronously to me (I have a MessageListener for that), but is not not what I need.
Is it possible that I can not use the same response queue for RabbitTemplate that I have for the MessageListener?
Thank you again Gary, and sorry because the question is really not clear.
I have a MessageListener working correctly when I send a message, but for some messages I need a synchronous reply. When I use the sendAndReceive method, I get the exception:
java.lang.IllegalStateException: RabbitTemplate is not configured as MessageListener - can not use a 'replyAddress': amq.gen-t1ESvGc4I8EfGJCjWjBxKw
And the RabbitTemplate has the property replyAddress : amq.gen-t1ESvGc4I8EfGJCjWjBxKw
If I use the method send, then the response arrives asynchronous to the MessageListener. But I need a synchronous response for some messages.
Upvotes: 0
Views: 1997
Reputation: 174769
Your question is not clear; if you want a synchronous reply then use sendAndReceive; the calling thread will block until the reply is received.
No, you can't use the same queue as the listener - they will compete for messages.
If you want async send and receive, the replyToAddress
can only be used with sendAndReceive
operations.
If you want to do async send and receive, you have to set the replyTo
property (queue name or exchange/routingKey
) in the message properties - before calling send
or in a MessagePostProcessor
when using sendAndReceive
.
You need to configure a listener container to receive the replies (which you said you have).
The upcoming 1.6 release has an AsyncRabbitTemplate
that has sendAndReceive
methods that return a ListenableFuture
; it's a convenience that wraps a RabbitTemplate
and SimpleMessageListenerContainer
for replies.
EDIT
You can't use the same reply queue for sync and async replies.
When using a fixed reply queue, you need to configure a reply listener container as described in the documentation.
However, you don't really need to specify a reply queue; the template will use Direct ReplyTo if the broker supports it (or a temporary queue otherwise).
If you must use a named reply queue (e.g. you need HA or the responding system doesn't use the replyTo property), then you must configure a reply listener (with the template being the listener).
Upvotes: 3