[rabbitmq-discuss] Using SelectConnection to simulate a blocking "basic_get"
mpietrek at skytap.com
Wed Aug 28 20:03:42 BST 2013
(I know this is Pika, rather than specifically RabbitMQ, but figure there's
a broader audience here.)
In our architecture, I'm investigating moving away from polling with
basic_get, and towards using basic_consume.
However, our twist is that our overall design doesn't just let us call
connection.io.loop.start() and handle all our messages inside the
registered handler like all the example code does.
What I'd like to do is something like the following, but I can't quite
figure out the combination of calls/callbacks to make it work.
- Create a "blocking" routine that either returns a message or "None" if
the whole system is shutting down:
- Let the broker push 1 message/time to us, rather than us polling via
Here's my admittedly incomplete thoughts on how this might work:
- Create a SelectConnection instance
- In the blocking read logic, use basic_consume to tell the broker it's
OK to send a message to us now (prefetch=1).
- call connection.ioloop.start()
- In the message handler, save off the message, then send a basic_cancel
to tell the broker "No more for now, thanks!"
- The connection.ioloop.start() returns to the caller
- Return the saved message to the caller.
- Wash, rinse, repeat...
Is this sane? Are there examples of how I might do this?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the rabbitmq-discuss