<div dir="ltr">To configure the retry advice in XML, you need to wire up a StatefulRetryOperationsInterceptorFactoryBean.<div><br></div><div>It needs a RetryTemplate (RetryOperations) bean which needs a RetryPolicy and BackOffPolicy beans.</div>
<div><br></div><div>Then wire the factory bean into the advice chain.</div><div><br></div><div>To set the message id, it depends on how you are sending messages; you can set it directly, or if you are using message conversion, set the createMessageIds to true on the outbound template's SimpleMessageConverter.</div>
<div><br></div><div>However, when using long backoffs like that, there's not much benefit in using stateful retry.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, May 20, 2014 at 3:29 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="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Thanks do you have xml version of the following?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">I need to set message id before publishing the message? How to do this?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Regards …</span><b><i><span style="font-size:24.0pt;font-family:Wingdings;color:#1f497d">?</span></i></b><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Srinath<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<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""> rabbitmq-discuss [mailto:<a href="mailto:rabbitmq-discuss-bounces@lists.rabbitmq.com" target="_blank">rabbitmq-discuss-bounces@lists.rabbitmq.com</a>]
<b>On Behalf Of </b>Gary Russell<br>
<b>Sent:</b> Tuesday, May 20, 2014 12:24 PM<br>
<b>To:</b> Discussions about RabbitMQ<br>
<b>Subject:</b> Re: [rabbitmq-discuss] Retry Message for 3 times with 10 seconds interval - in Consumer<u></u><u></u></span></p><div><div class="h5">
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New"">@Bean</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New"">public MethodInterceptor retryAdvice() {</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New""> FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy();</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New""> backOffPolicy.setBackOffPeriod(10000);;</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New""> return RetryInterceptorBuilder.stateful()</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New""> .backOffPolicy(backOffPolicy)</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New""> .maxAttempts(3)</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New""> .recoverer(new RejectAndDontRequeueRecoverer())</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New""> .build();</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New"">}</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Add it to the adviceChain property of the SimpleMessageListenerContainer.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Note: stateful retry requires the message to have a message id; use a stateless advice otherwise.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">After the retries are exhausted, the message will be rejected (and dropped or sent to a Dead Letter Exchange of so configured).<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><u></u> <u></u></p>
<div>
<p class="MsoNormal">On Tue, May 20, 2014 at 3:09 PM, Srinath Sridharan -X (srinatsr - ZENSAR TECHNOLOGIES INC at Cisco) <<a href="mailto:srinatsr@cisco.com" target="_blank">srinatsr@cisco.com</a>> wrote:<u></u><u></u></p>
<div>
<div>
<p class="MsoNormal"><span style="color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:#1f497d">Hello,</span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:#1f497d"> </span><u></u><u></u></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.
</span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:#1f497d"> </span><u></u><u></u></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><u></u><u></u></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></span><u></u><u></u></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></span><u></u><u></u></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></span><u></u><u></u></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><u></u><u></u></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><u></u><u></u></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><u></u><u></u></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><u></u><u></u></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></span><u></u><u></u></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><u></u><u></u></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></span><u></u><u></u></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></span><u></u><u></u></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><u></u><u></u></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><u></u><u></u></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><u></u><u></u></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><u></u><u></u></p>
<p class="MsoNormal"><span style="color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:#1f497d"> </span><u></u><u></u></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><u></u><u></u></p>
<p class="MsoNormal" style="text-autospace:none">
<span style="font-size:10.0pt;font-family:Consolas"> </span><u></u><u></u></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><u></u><u></u></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><u></u><u></u></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><u></u><u></u></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><u></u><u></u></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><u></u><u></u></p>
<p class="MsoNormal" style="text-autospace:none">
<span style="font-size:10.0pt;font-family:Consolas;color:#3f5fbf"> */</span><u></u><u></u></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><u></u><u></u></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><u></u><u></u></p>
<p class="MsoNormal" style="text-autospace:none">
<span style="font-size:10.0pt;font-family:Consolas"> </span><u></u><u></u></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><u></u><u></u></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><u></u><u></u></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><u></u><u></u></p>
<p class="MsoNormal" style="text-autospace:none">
<span style="font-size:10.0pt;font-family:Consolas;color:black"> }</span><u></u><u></u></p>
<p class="MsoNormal" style="text-autospace:none">
<span style="font-size:10.0pt;font-family:Consolas;color:black"> </span>
<u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:Consolas;color:black"> }</span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:#1f497d"> </span><u></u><u></u></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><u></u><u></u></p>
<p class="MsoNormal"><span style="color:#1f497d">Srinath</span><u></u><u></u></p>
</div>
<p class="MsoNormal"><span style="color:#1f497d"> </span><u></u><u></u></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</span><u></u><u></u></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><u></u><u></u></p>
<p class="MsoNormal"><span style="color:#1f497d">Srinath</span><span style="color:#888888"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#888888"> <u></u><u></u></span></p>
</div>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><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><u></u><u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div></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>