[rabbitmq-discuss] multiple threads in one queue

Marek Majkowski majek04 at gmail.com
Fri Oct 1 15:40:22 BST 2010

On Fri, Sep 24, 2010 at 12:35, Isaías <mcallus at gmail.com> wrote:
> In this moment, I have an unique channel and consumer in a main thread, it
> consume the queue and save the content in a normal java queue.
> The sons threads get the tasks from java queue, i want know how can I send
> one delay ack because my main thread can not follow consuming the rabbit
> queue if i does not send the ack inmediately.
> When the task finishs correctly in a son thread, it saves the task in a
> second queue that main thread read and send the ack for this task to
> eliminate the task from rabbit queue.
> Is it possible this??

So you pop messages from RabbitMQ queue and push it into a shared
data structure in Java. Java threads than pop messages from that
shared queue, do the work, and push a new message (ack) onto
another shared queue.

Main thread is responsible for receiving tasks from RabbitMQ and
popping acks from second shared queue and acknowledging them.

- yes, that sounds correct. Though, in my opinion you'll have issues
with the second bit - it's hard (impossible?) to wait both on RabbitMQ
events and on events from shared java queue.

Instead, I propose to send acknowledgments directly from your worker
threads. If I remember correctly, acks are thread-safe and can be
called from every thread.

> or is it better that i have one syncronize channel and
> one syncronize consumer and that all threads consume the rabbit queue?

It might be simpler to just have one AMQP connection for every
worker thread. Why not?


More information about the rabbitmq-discuss mailing list