<div dir="ltr">Hi Russell,<div><br></div><div>Thanks for the support. I have followed the documentation am getting response as null. Below is the producer and consumer code.</div><div><br></div><div>PRODUCER - </div><div><br>
</div><div><div>// rabbittemplate</div><div><div>public RabbitTemplate rabbitTemplate() {</div><div><span class="" style="white-space:pre">                </span>RabbitTemplate template = new RabbitTemplate(connectionFactory());</div><div>
<span class="" style="white-space:pre">                </span>template.setRoutingKey(this.queueName);</div><div><span class="" style="white-space:pre">                </span>template.setQueue(this.queueName);</div><div><span class="" style="white-space:pre">                </span>template.setMessageConverter(new JsonMessageConverter());</div>
<div><span class="" style="white-space:pre">                </span>return template;</div><div><span class="" style="white-space:pre">        </span>}</div></div><div><br></div></div><div>String msg = &quot;CUSTOMER1&quot;;</div><div><div>Object res = this.rabbitTemplate.convertSendAndReceive(msg);</div>
<div>System.out.println(&quot;Message sent :&quot; +msg);</div><div>System.out.println(&quot;Response : &quot; + res.toString());</div></div><div><br></div><div>CONSUMER - <br></div><div><br></div><div><div><span class="" style="white-space:pre">                </span>SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();</div>
<div><span class="" style="white-space:pre">                </span>container.setConnectionFactory(this.connectionFactory);</div><div><span class="" style="white-space:pre">                </span>container.setQueueNames(this.queueName);</div><div><span class="" style="white-space:pre">                </span>container.setMessageListener(new <b>MessageListenerAdapter</b>(new TestMessageHandler(this.queueName), new JsonMessageConverter()));</div>
<div><span class="" style="white-space:pre">                </span>container.start();</div></div><div><br></div><div><br></div><div><div>       // receive messages</div><div><span class="" style="white-space:pre">        </span>public void handleMessage(String msg) {</div>
<div><span class="" style="white-space:pre">                </span>System.out.println(&quot;Received  :&quot; + msg);</div><div><span class="" style="white-space:pre">        </span>} </div></div><div><br></div><div><div><b>Result - </b></div>
<div>Message sent :CUSTOMER1</div><div>java.lang.NullPointerException</div></div><div><br></div><div><br></div><div>Here, inside handleMessage based on message I want get the results from DB and need to send back. Am confusing how set the response to that client(Producer)?</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Nov 11, 2013 at 8:57 PM, Gary Russell <span dir="ltr">&lt;<a href="mailto:grussell@gopivotal.com" target="_blank">grussell@gopivotal.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Please read the documentation... <a href="http://docs.spring.io/spring-amqp/reference/html/amqp.html#d4e460" target="_blank">http://docs.spring.io/spring-amqp/reference/html/amqp.html#d4e460</a><div>
<br></div><div>It explains that, when you use a fixed reply queue, and roll your own configuration like this, you have to wire up a listener container for the replies (with the rabbitTemplate as the listener).</div>
<div><br></div><div>If you use a listener-container on the consumer side (with a MessageListenerAdapter), it will automatically send the result to the replyTo. Your consumer can be a simple POJO method that returns a list of Objects. Use a JsonMessageConverter in the adapter to convert them to JSON.<br>

</div><div><br></div><div><br></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Nov 11, 2013 at 9:56 AM, Rajasekhar P <span dir="ltr">&lt;<a href="mailto:sekhar434145@gmail.com" target="_blank">sekhar434145@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thank you Russell for the response. Still am stuck with achieving above program, could please tell where am failing while doing above code. Below is the code at producer end.<br>

<br><div><br></div><div><br></div>
<div>CONFIGURATION -</div><div><br></div><div>public RabbitTemplate rabbitTemplate() {</div><div><span style="white-space:pre-wrap">                </span>RabbitTemplate template = new RabbitTemplate(connectionFactory());</div><div>
<span style="white-space:pre-wrap">                </span>template.setRoutingKey(this.queueName);</div><div><span style="white-space:pre-wrap">                </span>template.setQueue(this.queueName);</div><div><span style="white-space:pre-wrap">                </span>template.setMessageConverter(new JsonMessageConverter());</div>


<div><span style="white-space:pre-wrap">                </span>return template;</div><div><span style="white-space:pre-wrap">        </span>}</div><div><br></div><div><span style="white-space:pre-wrap">        </span>public ConnectionFactory connectionFactory() {</div>


<div><span style="white-space:pre-wrap">                </span>CachingConnectionFactory connectionFactory = new CachingConnectionFactory(</div><div><span style="white-space:pre-wrap">                                </span>&quot;localhost&quot;);</div><div>
<span style="white-space:pre-wrap">                </span>connectionFactory.setUsername(&quot;guest&quot;);</div><div><span style="white-space:pre-wrap">                </span>connectionFactory.setPassword(&quot;guest&quot;);</div><div><span style="white-space:pre-wrap">                </span>return connectionFactory;</div>


<div><span style="white-space:pre-wrap">        </span>}</div><div><br></div><div><br></div><div>PRODUCER CODE -    </div><div><br></div><div><br></div><div><span style="white-space:pre-wrap">                        </span>String corrId = UUID.randomUUID().toString();</div>


<div><span style="white-space:pre-wrap">                        </span>String replyQueueName = <b>channel</b>.queueDeclare().getQueue();</div><div><span style="white-space:pre-wrap">                        </span></div><div><span style="white-space:pre-wrap">                        </span>MessageProperties prop = new MessageProperties();</div>


<div><span style="white-space:pre-wrap">                        </span>prop.setCorrelationId(corrId.getBytes());</div><div><span style="white-space:pre-wrap">                        </span>prop.setReplyTo(replyQueueName);</div><div><span style="white-space:pre-wrap">                        </span>Message message = new Message(query.getBytes(), prop);</div>


<div><span style="white-space:pre-wrap">                        </span>Message msg = rabbitTemplate.sendAndReceive(message);</div><div><br></div><div><br></div><div>Is this correct at producer end? Here how to Channel to retrieve reqplyQueueName? Could you please correct me on this and please tell me how to write consumer code to send the result(List of Objects) in JSON format back to that particular request in replyqueue? Thanks in advance.</div>


</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Nov 8, 2013 at 7:20 PM, Gary Russell <span dir="ltr">&lt;<a href="mailto:grussell@gopivotal.com" target="_blank">grussell@gopivotal.com</a>&gt;</span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><a href="http://docs.spring.io/spring-amqp/reference/html/amqp.html#request-reply" target="_blank">http://docs.spring.io/spring-amqp/reference/html/amqp.html#request-reply</a><br>


<div><br></div><div>The simplest is to configure the RabbitTemplate to use a fixed reply queue, with a reply listener, and use one of it&#39;s convertSendAndReceive(...) (or sendAndReceive) methods; the template will take care of the correlation.</div>



<div><br></div><div>If you want to do it asynchronously and do your own correlation (get the reply asynchronously on another thread) just use one of the send() methods and wire up a listener container to get the results.<br>



</div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div>On Fri, Nov 8, 2013 at 12:36 AM, Rajasekhar P <span dir="ltr">&lt;<a href="mailto:sekhar434145@gmail.com" target="_blank">sekhar434145@gmail.com</a>&gt;</span> wrote:<br>



</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr">Hi Team,<div><br></div><div>We are trying to make asynchronous call in RabbitMQ using Spring AMQP, could any one please tell me how to configure <b>replyqueue, correlationId, (properties) </b>using spring amqp?</div>




<div><pre style="background-color:rgb(238,238,238);padding:5px 15px;border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;color:rgb(85,85,85);font-size:13px;line-height:18px">
 <span style="color:rgb(0,128,128)">String</span> <span style="color:rgb(0,128,128)">corrId</span> <span style="font-weight:bold">=</span> <span style="color:rgb(0,128,128)">java</span><span style="font-weight:bold">.</span><span style="color:rgb(0,128,128)">util</span><span style="font-weight:bold">.</span><span style="color:rgb(0,128,128)">UUID</span><span style="font-weight:bold">.</span><span style="color:rgb(0,128,128)">randomUUID</span><span style="font-weight:bold">().</span><span style="color:rgb(0,128,128)">toString</span><span style="font-weight:bold">();</span>

<span style="color:rgb(0,128,128)"> BasicProperties</span> <span style="color:rgb(0,128,128)">props</span> <span style="font-weight:bold">=</span> <span style="font-weight:bold">new</span> <span style="color:rgb(0,128,128)">BasicProperties</span>
                                <span style="font-weight:bold">.</span><span style="color:rgb(0,128,128)">Builder</span><span style="font-weight:bold">()</span>
                                <span style="font-weight:bold">.</span><span style="color:rgb(0,128,128)">correlationId</span><span style="font-weight:bold">(</span><span style="color:rgb(0,128,128)">corrId</span><span style="font-weight:bold">)</span>
                                <span style="font-weight:bold">.</span><span style="color:rgb(0,128,128)">replyTo</span><span style="font-weight:bold">(</span><span style="color:rgb(0,128,128)">replyQueueName</span><span style="font-weight:bold">)</span>
                                <span style="font-weight:bold">.</span><span style="color:rgb(0,128,128)">build</span><span style="font-weight:bold">();</span>

 <span style="color:rgb(0,128,128)">channel</span><span style="font-weight:bold">.</span><span style="color:rgb(0,128,128)">basicPublish</span><span style="font-weight:bold">(</span><span style="color:rgb(221,17,68)">&quot;&quot;</span><span style="font-weight:bold">,</span> <span style="color:rgb(0,128,128)">requestQueueName</span><span style="font-weight:bold">,</span> <span style="color:rgb(0,128,128)">props</span><span style="font-weight:bold">,</span> <span style="color:rgb(0,128,128)">message</span><span style="font-weight:bold">.</span><span style="color:rgb(0,128,128)">getBytes</span><span style="font-weight:bold">());</span>
</pre></div><div><span style="font-weight:bold"><br></span></div><div><span>Thanks in advance.</span></div></div>
<br></div></div>_______________________________________________<br>
rabbitmq-discuss mailing list<br>
<a href="mailto:rabbitmq-discuss@lists.rabbitmq.com" target="_blank">rabbitmq-discuss@lists.rabbitmq.com</a><br>
<a href="https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss" target="_blank">https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss</a><br>
<br></blockquote></div><br></div>
<br>_______________________________________________<br>
rabbitmq-discuss mailing list<br>
<a href="mailto:rabbitmq-discuss@lists.rabbitmq.com" target="_blank">rabbitmq-discuss@lists.rabbitmq.com</a><br>
<a href="https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss" target="_blank">https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss</a><br>
<br></blockquote></div><br></div>
<br>_______________________________________________<br>
rabbitmq-discuss mailing list<br>
<a href="mailto:rabbitmq-discuss@lists.rabbitmq.com" target="_blank">rabbitmq-discuss@lists.rabbitmq.com</a><br>
<a href="https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss" target="_blank">https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss</a><br>
<br></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
rabbitmq-discuss mailing list<br>
<a href="mailto:rabbitmq-discuss@lists.rabbitmq.com">rabbitmq-discuss@lists.rabbitmq.com</a><br>
<a href="https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss" target="_blank">https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss</a><br>
<br></blockquote></div><br></div>