Async ack or nack

198 views
Skip to first unread message

Yair Ogen

unread,
Apr 10, 2016, 2:18:03 AM4/10/16
to rabbitmq-users
I have a need to handle the message in rabbitmq consumer callback, but ack the message or nack it in a different thread.

Is this possible? Does the rabbitmq design support this?

I'm asking as some Objects in the rabbit data-model are documented as not thread safe (specifically, the Channel in this case).

Michael Klishin

unread,
Apr 10, 2016, 6:13:07 AM4/10/16
to rabbitm...@googlegroups.com
It is technically if you ack on the same channel. But then you'd be sharing a channel between threads which is a really bad idea in most cases.

basic.ack is an asynchronous protocol method, there is no response to wait for.
--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yair Ogen

unread,
Apr 10, 2016, 7:30:10 AM4/10/16
to rabbitmq-users
My problem is not that the ACK API is blocking. it's not. My problem is - I'm using an async processing for my business logic (AKKA) and I only know if to ack or nack on another business thread.
Is there any lock I can apply on the channel to guarantee no  race conditions?

Michael Klishin

unread,
Apr 10, 2016, 7:33:30 AM4/10/16
to rabbitm...@googlegroups.com, Yair Ogen
There is no lock (except that you can lock on the channel object itself) and if you ack
messages one by one on the same channel, it doesn't matter what thread it happens on.

So pass the channel around together with delivery tag with your (Akka) messages
and ack that way.
--
MK

Staff Software Engineer, Pivotal/RabbitMQ


Izek Greenfield

unread,
Apr 10, 2016, 10:20:49 AM4/10/16
to rabbitmq-users
So if we ack all the messages from one thread it should be ok?

from my testing it does not work.

after about 1000 acks the client disconnects from the server without any error.

Michael Klishin

unread,
Apr 10, 2016, 10:44:29 AM4/10/16
to rabbitm...@googlegroups.com
The error is logged by the server.
--

Michael Klishin

unread,
Apr 10, 2016, 10:53:19 AM4/10/16
to rabbitm...@googlegroups.com
There are two requirements for acks:

 * Ack on the same channel the delivery was on
 * do not double ack

That's it.

On 10 abr 2016, at 17:20, Izek Greenfield <ize...@gmail.com> wrote:

--
Reply all
Reply to author
Forward
0 new messages