<div dir="ltr"><div class="gmail_default" style="font-family:tahoma,sans-serif">Hi Michael,</div><div class="gmail_default" style="font-family:tahoma,sans-serif"><br></div><div class="gmail_default" style><font face="tahoma, sans-serif">Ok, I can able to handle the exceptions while publishing the messages. As you mentioned I have set up the publisher confirm acknowledgement, and I published 10 messages to the exchange and I received all the 10 messages on my consumer but the acknowledgement is not coming for all the 10 messages.</font><span style="font-family:tahoma,sans-serif">I tried multiple times and I never received the acknowledgment for all my messages at all.</span></div>
<div class="gmail_default" style><span style="font-family:tahoma,sans-serif"><br></span></div><div class="gmail_default" style><span style="font-family:tahoma,sans-serif">Copied below my code and output. how can I identify the message along with the message contents for which didn't get the acknowledgement </span><span style="font-family:tahoma,sans-serif">?</span></div>
<div class="gmail_default" style><br><br><div class="gmail_default"><u><b>OUTPUT FOR CHANNEL ACKNOWLEDGEMENT: </b></u><br></div></div><div class="gmail_default" style><u><b><br></b></u><div class="gmail_default" style><font face="courier new, monospace" color="#666666">Received basic_ack: multiple = #<AMQ::Protocol::Basic::Ack:0x96d6560 @delivery_tag=5, @multiple=true>, delivery_tag = 5</font></div>
<div class="gmail_default" style><font face="courier new, monospace" color="#666666">Received basic_ack: multiple = #<AMQ::Protocol::Basic::Ack:0x96d5f84 @delivery_tag=6, @multiple=false>, delivery_tag = 6</font></div>
<div class="gmail_default" style><font face="courier new, monospace" color="#666666">Received basic_ack: multiple = #<AMQ::Protocol::Basic::Ack:0x96d5700 @delivery_tag=7, @multiple=false>, delivery_tag = 7</font></div>
<div class="gmail_default" style><font face="courier new, monospace" color="#666666">Received basic_ack: multiple = #<AMQ::Protocol::Basic::Ack:0x96d50c0 @delivery_tag=8, @multiple=false>, delivery_tag = 8</font></div>
<div class="gmail_default" style><font face="courier new, monospace" color="#666666">Received basic_ack: multiple = #<AMQ::Protocol::Basic::Ack:0x972ce10 @delivery_tag=10, @multiple=true>, delivery_tag = 10</font></div>
<div class="gmail_default" style><font face="courier new, monospace" color="#ff0000">Got acknowledgement for 5 messages only(I suspect RabbitMq sent </font><span style="color:rgb(255,0,0);font-family:'courier new',monospace">acknowledgement</span><span style="color:rgb(255,0,0);font-family:'courier new',monospace"> for </span><span style="color:rgb(255,0,0);font-family:'courier new',monospace">multiple messages on <b>5 & 10</b>)</span></div>
<div class="gmail_default" style><font face="tahoma, sans-serif"><br></font></div><div class="gmail_default" style><b><u>OUTPUT FROM CONSUMER (I increment the number while receiving the message)</u></b><font face="tahoma, sans-serif"><br>
</font></div><div class="gmail_default" style><font face="tahoma, sans-serif"><br></font></div><div class="gmail_default" style><font face="tahoma, sans-serif">1</font></div><div class="gmail_default" style><font face="tahoma, sans-serif">2</font></div>
<div class="gmail_default" style><font face="tahoma, sans-serif">3</font></div><div class="gmail_default" style><font face="tahoma, sans-serif">4</font></div><div class="gmail_default" style><font face="tahoma, sans-serif">5</font></div>
<div class="gmail_default" style><font face="tahoma, sans-serif">6</font></div><div class="gmail_default" style><font face="tahoma, sans-serif">7</font></div><div class="gmail_default" style><font face="tahoma, sans-serif">8</font></div>
<div class="gmail_default" style><font face="tahoma, sans-serif">9</font></div><div class="gmail_default" style><font face="tahoma, sans-serif">10<font color="#6aa84f"> # Received 10 messages in consumer</font></font></div>
<div style="font-family:tahoma,sans-serif"><br></div><div style="font-family:tahoma,sans-serif"><br></div><div style="font-family:tahoma,sans-serif"><b><u>CODE</u></b></div><div style="font-family:tahoma,sans-serif"><b><u><br>
</u></b></div><div style="font-family:tahoma,sans-serif"><div class="gmail_default" style="font-family:arial"><font color="#666666" face="courier new, monospace">ch1 = AMQP::Channel.new($connection)</font></div><div class="gmail_default" style="font-family:arial">
<font color="#666666" face="courier new, monospace">@ns_x = ch1.direct(ns_exchange, :durable => true)</font></div><div class="gmail_default" style="font-family:arial"><font color="#666666" face="courier new, monospace">@ns_queue = ch1.queue(ns_queue, :auto_delete => false)</font></div>
<div class="gmail_default" style="font-family:arial"><font color="#666666" face="courier new, monospace">@ns_queue.bind(@ns_x, :routing_key => @<a href="http://ns_queue.name">ns_queue.name</a>).subscribe(:ack => true, &method(:handle_ns_message))</font></div>
<div class="gmail_default" style="font-family:arial"><font color="#666666" face="courier new, monospace">ch1.confirm_select</font></div><div class="gmail_default" style="font-family:arial"><font color="#666666" face="courier new, monospace"><br>
</font></div><div class="gmail_default" style="font-family:arial"><font color="#666666" face="courier new, monospace">PUBLISH MESSAGE 10 times:</font></div><div class="gmail_default" style="font-family:arial"><font color="#666666" face="courier new, monospace">message_headers = {"messageType" => "ipam/operations/ip/checkCanAllocateIP"}</font></div>
<div class="gmail_default" style="font-family:arial"><font color="#666666" face="courier new, monospace">message_body = {"ipsToAllocate" => "1", "orgId" => "438c6cdd-aa2d-4f3c-bec3-aefb85d6fca5"}</font></div>
<div class="gmail_default" style="font-family:arial"><font color="#666666" face="courier new, monospace">10.times do</font></div><div class="gmail_default" style="font-family:arial"><font color="#666666" face="courier new, monospace">@ns_x.publish(message_body, :routing_key => "ipamAgent.operations", :headers => message_headers, :mandatory => true)</font></div>
<div class="gmail_default" style="font-family:arial"><font color="#666666" face="courier new, monospace">end</font></div><div class="gmail_default" style="font-family:arial"><font color="#666666" face="courier new, monospace"><br>
</font></div><div class="gmail_default" style="font-family:arial"><font color="#666666" face="courier new, monospace">ch1.on_ack do |basic_ack|</font></div><div class="gmail_default" style="font-family:arial"><font color="#666666" face="courier new, monospace"> puts "Received basic_ack: multiple = #{basic_ack.multiple}, delivery_tag = #{basic_ack.delivery_tag}"</font></div>
<div class="gmail_default" style="font-family:arial"><font color="#666666" face="courier new, monospace">end</font></div><div class="gmail_default" style="font-family:arial"><br></div><u style="font-family:arial"></u></div>
</div></div><div class="gmail_extra"><br clear="all"><div><font style="font-family:tahoma,sans-serif" face="tahoma, sans-serif">regards,<br>Loganathan<br>Mob: +91 7760780741 | +91 9944414388<br>Skype: loganathan.sellappa<br>
</font><span style="font-family:tahoma,sans-serif"><a href="http://vizualize.me/loganathan" target="_blank">ViewMe</a></span><br><br></div>
<br><br><div class="gmail_quote">On Mon, Apr 28, 2014 at 4:50 PM, Michael Klishin <span dir="ltr"><<a href="mailto:mklishin@gopivotal.com" target="_blank">mklishin@gopivotal.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class=""> On 28 April 2014 at 15:17:34, Loganathan Sellapa (<a href="mailto:loganathan.ms@gmail.com">loganathan.ms@gmail.com</a>) wrote:<br>
> > So I assumed that RabbitMq will re-publish the message automatically,<br>
> whenever RabbitMq recovered from failover case.<br>
<br>
</div>That’s not true.<br>
<div class=""><br>
> My question<br>
> is how can I make publish the message(from producer to RabbitMq<br>
> broker), when some exceptions occurred while publishing the<br>
> message to rabbitMq channel. Below is my sample code for it.<br>
<br>
</div>Handle exceptions from Exchange#publish. Note that this does not cover<br>
cases when EventMachine event loop just dies under you but there’s nothing<br>
amqp gem can do.<br>
<br>
This is also why unless you already use EventMachine heavily, you<br>
should use Bunny or March Hare:<br>
<br>
<a href="https://github.com/ruby-amqp/amqp#a-word-of-warning-use-this-only-if-you-already-use-eventmachine" target="_blank">https://github.com/ruby-amqp/amqp#a-word-of-warning-use-this-only-if-you-already-use-eventmachine</a><br>
<div class="HOEnZb"><div class="h5">--<br>
MK<br>
<br>
Software Engineer, Pivotal/RabbitMQ<br>
</div></div></blockquote></div><br></div>