<div dir="ltr"><div><span class="" style="white-space:pre"><font face="courier new, monospace">@Bean</font></span></div><div><span class="" style="white-space:pre"><font face="courier new, monospace">public MethodInterceptor retryAdvice() {</font></span></div>
<div><font face="courier new, monospace"><span class="" style="white-space:pre">        </span>FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy();</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">      </span>backOffPolicy.setBackOffPeriod(10000);;</font></div>
<div><span class="" style="font-family:'courier new',monospace;white-space:pre">        return </span><span style="font-family:'courier new',monospace">RetryInterceptorBuilder.stateful()</span><br></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">             </span>.backOffPolicy(backOffPolicy)</font></div>
<div><font face="courier new, monospace"><span class="" style="white-space:pre">                </span>.maxAttempts(3)</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">           </span>.recoverer(new RejectAndDontRequeueRecoverer())<br>
</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">               </span>.build();</font></div><div><font face="courier new, monospace">}</font></div><div><br></div><div>Add it to the adviceChain property of the SimpleMessageListenerContainer.</div>
<div><br></div><div>Note: stateful retry requires the message to have a message id; use a stateless advice otherwise.</div><div><br></div><div>After the retries are exhausted, the message will be rejected (and dropped or sent to a Dead Letter Exchange of so configured).</div>
<div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, May 20, 2014 at 3:09 PM, Srinath Sridharan -X (srinatsr - ZENSAR TECHNOLOGIES INC at Cisco) <span dir="ltr"><<a href="mailto:srinatsr@cisco.com" target="_blank">srinatsr@cisco.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div lang="EN-US" link="blue" vlink="purple">
<div>
<p class="MsoNormal"><span style="color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:#1f497d">Hello,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:#1f497d">I am consuming the messages using the listener as follows,  I need to retry processing three times if any exceptions occurred. 
<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:teal"><</span><span style="font-size:10.0pt;font-family:Consolas;color:#3f7f7f">bean</span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>

<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas">       
<span style="color:#7f007f">class</span><span style="color:black">=</span><i><span style="color:#2a00ff">"org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer"</span></i><span style="color:teal">></span><u></u><u></u></span></p>

<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:black">       
</span><span style="font-size:10.0pt;font-family:Consolas;color:teal"><</span><span style="font-size:10.0pt;font-family:Consolas;color:#3f7f7f">property</span><span style="font-size:10.0pt;font-family:Consolas">
<span style="color:#7f007f">name</span><span style="color:black">=</span><i><span style="color:#2a00ff">"connectionFactory"</span></i>
<span style="color:#7f007f">ref</span><span style="color:black">=</span><i><span style="color:#2a00ff">"connectionFactory"</span></i>
<span style="color:teal">/></span><u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:black">       
</span><span style="font-size:10.0pt;font-family:Consolas;color:teal"><</span><span style="font-size:10.0pt;font-family:Consolas;color:#3f7f7f">property</span><span style="font-size:10.0pt;font-family:Consolas">
<span style="color:#7f007f">name</span><span style="color:black">=</span><i><span style="color:#2a00ff">"queueNames"</span></i><span style="color:teal">></span><u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:black">           
</span><span style="font-size:10.0pt;font-family:Consolas;color:teal"><</span><span style="font-size:10.0pt;font-family:Consolas;color:#3f7f7f">array</span><span style="font-size:10.0pt;font-family:Consolas;color:teal">></span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>

<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:black">               
</span><span style="font-size:10.0pt;font-family:Consolas;color:teal"><</span><span style="font-size:10.0pt;font-family:Consolas;color:#3f7f7f">value</span><span style="font-size:10.0pt;font-family:Consolas;color:teal">></span><span style="font-size:10.0pt;font-family:Consolas;color:black">validateRequestQueue</span><span style="font-size:10.0pt;font-family:Consolas;color:teal"></</span><span style="font-size:10.0pt;font-family:Consolas;color:#3f7f7f">value</span><span style="font-size:10.0pt;font-family:Consolas;color:teal">></span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>

<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:black">           
</span><span style="font-size:10.0pt;font-family:Consolas;color:teal"></</span><span style="font-size:10.0pt;font-family:Consolas;color:#3f7f7f">array</span><span style="font-size:10.0pt;font-family:Consolas;color:teal">></span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>

<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:black">       
</span><span style="font-size:10.0pt;font-family:Consolas;color:teal"></</span><span style="font-size:10.0pt;font-family:Consolas;color:#3f7f7f">property</span><span style="font-size:10.0pt;font-family:Consolas;color:teal">></span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>

<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:black">       
</span><span style="font-size:10.0pt;font-family:Consolas;color:teal"><</span><span style="font-size:10.0pt;font-family:Consolas;color:#3f7f7f">property</span><span style="font-size:10.0pt;font-family:Consolas">
<span style="color:#7f007f">name</span><span style="color:black">=</span><i><span style="color:#2a00ff">"messageListener"</span></i><span style="color:teal">></span><u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:black">           
</span><span style="font-size:10.0pt;font-family:Consolas;color:teal"><</span><span style="font-size:10.0pt;font-family:Consolas;color:#3f7f7f">bean</span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>

<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas">               
<span style="color:#7f007f">class</span><span style="color:black">=</span><i><span style="color:#2a00ff">"org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter"</span></i><span style="color:teal">></span><u></u><u></u></span></p>

<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:black">               
</span><span style="font-size:10.0pt;font-family:Consolas;color:teal"><</span><span style="font-size:10.0pt;font-family:Consolas;color:#3f7f7f">property</span><span style="font-size:10.0pt;font-family:Consolas">
<span style="color:#7f007f">name</span><span style="color:black">=</span><i><span style="color:#2a00ff">"delegate"</span></i>
<span style="color:#7f007f">ref</span><span style="color:black">=</span><i><span style="color:#2a00ff">"retryConsumer"</span></i>
<span style="color:teal">/></span><u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:black">           
</span><span style="font-size:10.0pt;font-family:Consolas;color:teal"></</span><span style="font-size:10.0pt;font-family:Consolas;color:#3f7f7f">bean</span><span style="font-size:10.0pt;font-family:Consolas;color:teal">></span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>

<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:black">       
</span><span style="font-size:10.0pt;font-family:Consolas;color:teal"></</span><span style="font-size:10.0pt;font-family:Consolas;color:#3f7f7f">property</span><span style="font-size:10.0pt;font-family:Consolas;color:teal">></span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>

<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:black">       
</span><span style="font-size:10.0pt;font-family:Consolas;color:#3f5fbf"><!-- <property name="acknowledgeMode" value="NONE" /> --></span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>

<p class="MsoNormal"><span style="font-size:10.0pt;font-family:Consolas;color:black">   
</span><span style="font-size:10.0pt;font-family:Consolas;color:teal"></</span><span style="font-size:10.0pt;font-family:Consolas;color:#3f7f7f">bean</span><span style="font-size:10.0pt;font-family:Consolas;color:teal">></span><span style="color:#1f497d"><u></u><u></u></span></p>

<p class="MsoNormal"><span style="color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><b><span style="font-size:10.0pt;font-family:Consolas;color:#7f0055">public</span></b><span style="font-size:10.0pt;font-family:Consolas;color:black">
</span><b><span style="font-size:10.0pt;font-family:Consolas;color:#7f0055">class</span></b><span style="font-size:10.0pt;font-family:Consolas;color:black"> RetryConsumer
</span><b><span style="font-size:10.0pt;font-family:Consolas;color:#7f0055">implements</span></b><span style="font-size:10.0pt;font-family:Consolas;color:black"> ChannelAwareMessageListener {</span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>

<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas"><u></u> <u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:black">      
</span><span style="font-size:10.0pt;font-family:Consolas;color:#3f5fbf">/**</span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:#3f5fbf">       * Callback for processing a received Rabbit message.</span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>

<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:#3f5fbf">       *
</span><b><span style="font-size:10.0pt;font-family:Consolas;color:#7f9fbf">@param</span></b><span style="font-size:10.0pt;font-family:Consolas;color:#3f5fbf"> message the received AMQP message</span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>

<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:#3f5fbf">       *
</span><b><span style="font-size:10.0pt;font-family:Consolas;color:#7f9fbf">@param</span></b><span style="font-size:10.0pt;font-family:Consolas;color:#3f5fbf"> channel the underlying Rabbit Channel</span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>

<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:#3f5fbf">       *
</span><b><span style="font-size:10.0pt;font-family:Consolas;color:#7f9fbf">@throws</span></b><span style="font-size:10.0pt;font-family:Consolas;color:#3f5fbf"> Exception
</span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:#3f5fbf">        */</span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:black">      
</span><span style="font-size:10.0pt;font-family:Consolas;color:#646464">@Override</span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:black">      
</span><b><span style="font-size:10.0pt;font-family:Consolas;color:#7f0055">public</span></b><span style="font-size:10.0pt;font-family:Consolas;color:black">
</span><b><span style="font-size:10.0pt;font-family:Consolas;color:#7f0055">void</span></b><span style="font-size:10.0pt;font-family:Consolas;color:black"> onMessage(Message message, Channel channel)
</span><b><span style="font-size:10.0pt;font-family:Consolas;color:#7f0055">throws</span></b><span style="font-size:10.0pt;font-family:Consolas;color:black"> Exception {</span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>

<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas"><u></u> <u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:black">             System.</span><i><span style="font-size:10.0pt;font-family:Consolas;color:#0000c0">out</span></i><span style="font-size:10.0pt;font-family:Consolas;color:black">.println(</span><span style="font-size:10.0pt;font-family:Consolas;color:#2a00ff">"Received
 Message :: "</span><span style="font-size:10.0pt;font-family:Consolas;color:black">+</span><b><span style="font-size:10.0pt;font-family:Consolas;color:#7f0055">new</span></b><span style="font-size:10.0pt;font-family:Consolas;color:black"> String(message.getBody()));</span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>

<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:black">            
</span><b><span style="font-size:10.0pt;font-family:Consolas;color:#7f0055">if</span></b><span style="font-size:10.0pt;font-family:Consolas;color:black">(</span><b><span style="font-size:10.0pt;font-family:Consolas;color:#7f0055">true</span></b><span style="font-size:10.0pt;font-family:Consolas;color:black">){</span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>

<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:black">            
</span><b><span style="font-size:10.0pt;font-family:Consolas;color:#7f0055">throw</span></b><span style="font-size:10.0pt;font-family:Consolas;color:black">
</span><b><span style="font-size:10.0pt;font-family:Consolas;color:#7f0055">new</span></b><span style="font-size:10.0pt;font-family:Consolas;color:black"> RuntimeException(</span><span style="font-size:10.0pt;font-family:Consolas;color:#2a00ff">"Error"</span><span style="font-size:10.0pt;font-family:Consolas;color:black">);</span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>

<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:black">             }</span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:black">            
</span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:Consolas;color:black">       }</span><span style="color:#1f497d"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#1f497d"><u></u> <u></u></span></p>
<div>
<p class="MsoNormal"><span style="color:#1f497d">Regards …</span><b><i><span style="font-size:24.0pt;font-family:Wingdings;color:#1f497d">?</span></i></b><span style="color:#1f497d"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#1f497d">Srinath<u></u><u></u></span></p>
</div>
<p class="MsoNormal"><span style="color:#1f497d"><u></u> <u></u></span></p>
<div>
<div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Srinath Sridharan -X (srinatsr - ZENSAR TECHNOLOGIES INC at Cisco)
<br>
<b>Sent:</b> Monday, May 19, 2014 10:47 AM<br>
<b>To:</b> <a href="mailto:rabbitmq-discuss@lists.rabbitmq.com" target="_blank">rabbitmq-discuss@lists.rabbitmq.com</a><br>
<b>Subject:</b> Retry Message for 3 times with 10 seconds interval - in Consumer<u></u><u></u></span></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p>Retry unacknowledged RabbitMQ message in 10 second interval
<u></u><u></u></p>
<p>And Retry 3 times using Spring framework in java .<u></u><u></u></p>
<p><u></u> <u></u></p>
<p>Please need help on this<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><span style="color:#1f497d">Regards …</span><b><i><span style="font-size:24.0pt;font-family:Wingdings;color:#1f497d">?</span></i></b><span class="HOEnZb"><font color="#888888"><span style="color:#1f497d"><u></u><u></u></span></font></span></p>
<span class="HOEnZb"><font color="#888888">
<p class="MsoNormal"><span style="color:#1f497d">Srinath<u></u><u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></p>
</font></span></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>