[rabbitmq-discuss] RabbitMQ and Spring
david_syer at hotmail.com
Mon Aug 15 10:18:30 BST 2011
Arno Puschmann wrote:
> But i can't explain why i get always null as a response.
> template.setExchange("exchange"); //direct and durable
> Message response = template.sendAndReceive("exchange", "anotherQueue" ,
I think you need to get down to basics with what the RabbitTemplate is doing
behind the scenes here. Your expectations do not seem to match the
In this code snippet, you first set the default exchange for sending
messages, and then use an explicit value in your call to sendAndReceive(),
so the first line is redundant.
In the third line you set the default routing key, and then don't use it, so
that line is redundant.
The second line does nothing because that sets the default queue for
receive() calls, which is not used by sendAndReceive().
So you have sent a message to an exchange called "exchange" with routing key
"anotherQueue". The message will have a reply-to header added by the
template which your consumer should respect. If the consumer replies to the
correct address (it will be a temporary exclusive queue) then you will
receive the reply in your response variable.
I know the javadocs for RabbitTemplate are pretty thin. You can read the
source code to work out all of the above, but please feel free to raise a
JIRA ticket to get the docs improved as well. Thank you.
View this message in context: http://old.nabble.com/RabbitMQ-and-Spring-tp32137903p32263108.html
Sent from the RabbitMQ mailing list archive at Nabble.com.
More information about the rabbitmq-discuss