<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: tahoma,new york,times,serif; font-size: 12pt; color: #000000'>As I mentioned on the Spring forum - the rabbit template will use the same channel as the listener (by default). If the listener is transactional, the send won't complete until the transaction commits (handler exits).<div><br></div><div><a href="http://forum.springsource.org/showthread.php?135102-Problems-when-sending-a-message-while-receiving-using-RabbitMQ-RabbitTemplate&amp;p=439178&amp;posted=1#post439178">http://forum.springsource.org/showthread.php?135102-Problems-when-sending-a-message-while-receiving-using-RabbitMQ-RabbitTemplate&amp;p=439178&amp;posted=1#post439178</a><br><br><hr id="zwchr"><div style="color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>From: </b>"Marco Pas" &lt;marco.pasopas@gmail.com&gt;<br><b>To: </b>rabbitmq-discuss@googlegroups.com<br><b>Sent: </b>Friday, February 22, 2013 9:06:52 AM<br><b>Subject: </b>[rabbitmq-discuss] Problems when sending a message while receiving<br><br><span style="font-family: arial, sans-serif;">HI there i am trying to send a message in the handleMessage method,</span><br style="font-family: arial, sans-serif;"><span style="font-family: arial, sans-serif;">this seems to fail somehow. Is there a reason why i cannot send a</span><br style="font-family: arial, sans-serif;"><span style="font-family: arial, sans-serif;">message to rabbitMQ when processing a message?</span><br style="font-family: arial, sans-serif;"><br style="font-family: arial, sans-serif;"><span style="font-family: arial, sans-serif;">// receives a message and replies to the reply queue</span><br style="font-family: arial, sans-serif;"><span style="font-family: arial, sans-serif;">void handleMessage(Message message) {</span><br style="font-family: arial, sans-serif;"><br style="font-family: arial, sans-serif;"><span style="font-family: arial, sans-serif;">&nbsp; &nbsp; // send a message to the exchange and waits for the reply..</span><br style="font-family: arial, sans-serif;"><span style="font-family: arial, sans-serif;">&nbsp; &nbsp; String result =</span><br style="font-family: arial, sans-serif;"><span style="font-family: arial, sans-serif;">rabbitTemplate.</span><span style="font-family: arial, sans-serif;">convertSendAndReceive("</span><span style="font-family: arial, sans-serif;">myCustomExch", "myRoutingKey",</span><br style="font-family: arial, sans-serif;"><span style="font-family: arial, sans-serif;">"test content")</span><br style="font-family: arial, sans-serif;"><br style="font-family: arial, sans-serif;"><span style="font-family: arial, sans-serif;">&nbsp; &nbsp; // determine the reply queue</span><br style="font-family: arial, sans-serif;"><span style="font-family: arial, sans-serif;">&nbsp; &nbsp; def destQueue = message.messageProperties.</span><span style="font-family: arial, sans-serif;">replyTo</span><br style="font-family: arial, sans-serif;"><br style="font-family: arial, sans-serif;"><span style="font-family: arial, sans-serif;">&nbsp; &nbsp; // code omitted that processes the message and uses the previously result</span><br style="font-family: arial, sans-serif;"><span style="font-family: arial, sans-serif;">&nbsp; &nbsp; ....</span><br style="font-family: arial, sans-serif;"><br style="font-family: arial, sans-serif;"><span style="font-family: arial, sans-serif;">&nbsp; &nbsp; // send the content back to the reply queue</span><br style="font-family: arial, sans-serif;"><span style="font-family: arial, sans-serif;">&nbsp; &nbsp; rabbitSend destQueue, responseJson</span><br style="font-family: arial, sans-serif;"><span style="font-family: arial, sans-serif;">}</span><br style="font-family: arial, sans-serif;"><br style="font-family: arial, sans-serif;"><span style="font-family: arial, sans-serif;">When i put the rabbitTemplate.</span><span style="font-family: arial, sans-serif;">convertSendAndReceive("</span><span style="font-family: arial, sans-serif;">myCustomExch",</span><br style="font-family: arial, sans-serif;"><span style="font-family: arial, sans-serif;">"myRoutingKey", "test content") method in a non handleMessage method</span><br style="font-family: arial, sans-serif;"><span style="font-family: arial, sans-serif;">it works without problems. Am i not allowed to send and receive inside</span><br style="font-family: arial, sans-serif;"><span style="font-family: arial, sans-serif;">a handleMessage method that is also handling stuf?</span><br><div><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;">/Marco</span></div><br>_______________________________________________<br>rabbitmq-discuss mailing list<br>rabbitmq-discuss@lists.rabbitmq.com<br>https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss<br></div><br></div></div></body></html>