[rabbitmq-discuss] Can a Publish be acknowledged.

Alexandru Scvorţov alexandru at rabbitmq.com
Fri Sep 9 01:34:01 BST 2011


> I'd effectively like an acknowledgment to say "this message was put on to at
> least one queue".
> 
> is this possible?

Yes.

Strictly speaking, you're asking about messages published with the
mandatory flag enabled.  Such a message *must* reach a queue; if it
doesn't, you get a basic.return back.  That said, it's probably not
exactly what you want.  You'll know messages published like this have
reached a queue, but that alone gives you no guarantee that the message
will survive a broker restart.

You probably want publisher acknowledgements for that, aka confirm mode.
After a channel is put into a confirm mode, the broker acknowledges every
publish.  An acknowledgement in this case means "the message has been
handled somehow; don't worry about it"; this usually means that either
the message has reached some queues and was written to disk (and so will
survive a broker death) or that it was delivered to consumers which have
also acknowledged it.

To get the acknowledgement you want, you need to publish both with
mandatory set and to a confirm channel.  If you get a basic.return and
an acknowledgement, that means the message was not delivered to any
queues; if you get just an acknowledgement, that means the broker has
handled the message somehow; if you get a nack, that means the message
was probably lost in some way, so you need to resend it or something.
The broker guarantees that it will eventually acknowledge or nack all
messages published to confirm channels.

See the documentation for IModel:
http://www.rabbitmq.com/releases/rabbitmq-dotnet-client/v2.6.0/rabbitmq-dotnet-client-2.6.0-client-htmldoc/html/type-RabbitMQ.Client.IModel.html

You're looking for ConfirmSelect, to enable confirm mode, BasicPublish,
with mandatory set, and BasicAckEventHandler, BasicNackEventHandler,
BasicReturnEventHandler for the interesting events.

Alternatively, if you're feeling lazy, you can use the new (introduced
in 2.6.0) IModel.WaitForConfirms.  The function waits for all messages
published on the channel so far to be acknowledged or nack'd and returns
true if all of them were acknowledged (or false if some were nack'd).
So, to use it, you'd enable confirm mode with ConfirmSelect, publish
some messages, and call WaitForConfirms.  Note that this does not
handle the case were messages were not routed to any queues (i.e.
basic.returns) and calling it after every message is going to hurt
performance quite a bit.

Hope this helps.

Cheers,
Alex

On Fri, Sep 09, 2011 at 09:53:51AM +1000, Tim Yen wrote:
> Hi,
> 
> I'm using Rabbit MQ in .net
> 
> What I need to do is get some acknowledgement that a publish has been
> successful to an exchange bound to a persistent queue.
> 
> I know the queue name and the exchange name.
> 
> I'd effectively like an acknowledgment to say "this message was put on to at
> least one queue".
> 
> is this possible?
> 
> Tim

> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss



More information about the rabbitmq-discuss mailing list