[rabbitmq-discuss] [RUBY-AMQP GEM] How do we can retry publish message on errors?
Loganathan Sellapa
loganathan.ms at gmail.com
Mon Apr 28 13:46:43 BST 2014
Hi Michael,
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.I
tried multiple times and I never received the acknowledgment for all my
messages at all.
Copied below my code and output. how can I identify the message along with
the message contents for which didn't get the acknowledgement ?
*OUTPUT FOR CHANNEL ACKNOWLEDGEMENT: *
Received basic_ack: multiple = #<AMQ::Protocol::Basic::Ack:0x96d6560
@delivery_tag=5, @multiple=true>, delivery_tag = 5
Received basic_ack: multiple = #<AMQ::Protocol::Basic::Ack:0x96d5f84
@delivery_tag=6, @multiple=false>, delivery_tag = 6
Received basic_ack: multiple = #<AMQ::Protocol::Basic::Ack:0x96d5700
@delivery_tag=7, @multiple=false>, delivery_tag = 7
Received basic_ack: multiple = #<AMQ::Protocol::Basic::Ack:0x96d50c0
@delivery_tag=8, @multiple=false>, delivery_tag = 8
Received basic_ack: multiple = #<AMQ::Protocol::Basic::Ack:0x972ce10
@delivery_tag=10, @multiple=true>, delivery_tag = 10
Got acknowledgement for 5 messages only(I suspect RabbitMq sent
acknowledgement for multiple messages on *5 & 10*)
*OUTPUT FROM CONSUMER (I increment the number while receiving the message)*
1
2
3
4
5
6
7
8
9
10 # Received 10 messages in consumer
*CODE*
ch1 = AMQP::Channel.new($connection)
@ns_x = ch1.direct(ns_exchange, :durable => true)
@ns_queue = ch1.queue(ns_queue, :auto_delete => false)
@ns_queue.bind(@ns_x, :routing_key => @ns_queue.name).subscribe(:ack =>
true, &method(:handle_ns_message))
ch1.confirm_select
PUBLISH MESSAGE 10 times:
message_headers = {"messageType" => "ipam/operations/ip/checkCanAllocateIP"}
message_body = {"ipsToAllocate" => "1", "orgId" =>
"438c6cdd-aa2d-4f3c-bec3-aefb85d6fca5"}
10.times do
@ns_x.publish(message_body, :routing_key => "ipamAgent.operations",
:headers => message_headers, :mandatory => true)
end
ch1.on_ack do |basic_ack|
puts "Received basic_ack: multiple = #{basic_ack.multiple}, delivery_tag
= #{basic_ack.delivery_tag}"
end
regards,
Loganathan
Mob: +91 7760780741 | +91 9944414388
Skype: loganathan.sellappa
ViewMe <http://vizualize.me/loganathan>
On Mon, Apr 28, 2014 at 4:50 PM, Michael Klishin <mklishin at gopivotal.com>wrote:
> On 28 April 2014 at 15:17:34, Loganathan Sellapa (loganathan.ms at gmail.com)
> wrote:
> > > So I assumed that RabbitMq will re-publish the message automatically,
> > whenever RabbitMq recovered from failover case.
>
> That’s not true.
>
> > My question
> > is how can I make publish the message(from producer to RabbitMq
> > broker), when some exceptions occurred while publishing the
> > message to rabbitMq channel. Below is my sample code for it.
>
> Handle exceptions from Exchange#publish. Note that this does not cover
> cases when EventMachine event loop just dies under you but there’s nothing
> amqp gem can do.
>
> This is also why unless you already use EventMachine heavily, you
> should use Bunny or March Hare:
>
>
> https://github.com/ruby-amqp/amqp#a-word-of-warning-use-this-only-if-you-already-use-eventmachine
> --
> MK
>
> Software Engineer, Pivotal/RabbitMQ
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20140428/65729c7d/attachment.html>
More information about the rabbitmq-discuss
mailing list