[rabbitmq-discuss] Can a Publish be acknowledged.

272 views
Skip to first unread message

Tim Yen

unread,
Sep 8, 2011, 7:53:51 PM9/8/11
to rabbitmq...@lists.rabbitmq.com
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

Alexandru Scvorţov

unread,
Sep 8, 2011, 8:34:01 PM9/8/11
to Tim Yen, rabbitmq...@lists.rabbitmq.com
> 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

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

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

Tim Yen

unread,
Oct 4, 2011, 3:10:27 AM10/4/11
to rabbitmq...@lists.rabbitmq.com
Alexandru Scvorţov <alexandru@...> writes:

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

> 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.
>

> Alternatively, if you're feeling lazy, you can use the new (introduced


> in 2.6.0) IModel.WaitForConfirms. The function waits for all messages
>

> Hope this helps.
>
> Cheers,
> Alex
>

Thanks Alex,

After enabling confirm select how can I know which message is being confirmed or
nacked by the various callbacks assuming that its all asynchronous?

The BasicAckEvent and Nack event handlers have the DeliveryTag but how do i get
this number on BasicPublish?

Also the BasicReturnEventArgs has no DeliveryTag. Can I just ignore the
BasicReturn and rely on only the Ack and Nack event handlers?

As I dont need the performance WaitForConfirms seems to be the go but it doesn't
appear to be implemented in the .net code. It seems to
be Java only. Maybe its hidden somewhere anybody know?

Maybe someone can post the Java for the WaitForConfirms and I can morph it to c#

Matthias Radestock

unread,
Oct 4, 2011, 3:31:34 AM10/4/11
to Tim Yen, rabbitmq...@lists.rabbitmq.com
Tim,

On 04/10/11 08:10, Tim Yen wrote:
> After enabling confirm select how can I know which message is being confirmed or
> nacked by the various callbacks assuming that its all asynchronous?
>
> The BasicAckEvent and Nack event handlers have the DeliveryTag but how do i get
> this number on BasicPublish?

Publishes are numbered sequentially. The BasicAck/Nack delivery tag
contains that sequence number.

In the RabbitMQ clients the channel ("IModel" in the .net client
terminology) keeps track of the sequence number. See
http://www.rabbitmq.com/releases/rabbitmq-dotnet-client/v2.6.1/rabbitmq-dotnet-client-2.6.1-client-htmldoc/html/type-RabbitMQ.Client.IModel.html#property-P:RabbitMQ.Client.IModel.NextPublishSeqNo

> Also the BasicReturnEventArgs has no DeliveryTag. Can I just ignore the
> BasicReturn and rely on only the Ack and Nack event handlers?

You cannot. When a broker confirms a message it is telling the client
that it has taken responsibility for it. One way the broker can
discharge its responsibility is by returning the message. Hence messages
returned with basic.return are *ack*ed, not nack'ed.

> As I dont need the performance WaitForConfirms seems to be the go but it doesn't
> appear to be implemented in the .net code. It seems to
> be Java only. Maybe its hidden somewhere anybody know?

It's not exactly hidden:

http://www.rabbitmq.com/releases/rabbitmq-dotnet-client/v2.6.1/rabbitmq-dotnet-client-2.6.1-client-htmldoc/html/type-RabbitMQ.Client.IModel.html#method-M:RabbitMQ.Client.IModel.WaitForConfirms


Matthias.

Reply all
Reply to author
Forward
0 new messages