[rabbitmq-discuss] How to get notification when a queue becomes non-empty without removing any messages?

vitaly vitaly.krugl.numenta at gmail.com
Tue Sep 10 20:33:21 BST 2013


On Monday, September 9, 2013 4:20:09 PM UTC-7, vitaly wrote:
>
> I need to be able to spawn a consumer process for a queue when that queue 
> becomes non-empty. The trigger needs to happen in an event-driven way, 
> without polling, and without removing any messages from that queue. Is this 
> possible with AMQP/RabbitMQ and how?  I am coding in Python.
>
> Thank you,
> Vitaly
>
The following reply was posted to the rabbitmq-discuss mailing list by 
Michael Laing:
==
To: Discussions about RabbitMQ <rabbitmq-discuss at lists.rabbitmq.com>
Message-ID:
<CAKgmDnGcTdWhsdHN2hcGCTJmv8iUNa9dGfOVjD1CtHWU5bPQnw at mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Why don't you just subscribe to that queue with basic.consume, acks on, and
a prefetch of 1

When you get a message, reject it and cancel your consumer (if your logic
calls for it).

The message will be at the front of the queue.

Then spawn your 'consumer process'. The message (and any others) will be
there waiting.

I use python pika async to do this sort of thing. Event driven, no polling.

If speed is important, use the tornado adapter; if you are feeling lucky,
use the libev adapter (full disclosure: I wrote it)

-ml
==
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20130910/a60988a9/attachment.htm>


More information about the rabbitmq-discuss mailing list