gmr / rabbitpy

A pure python, thread-safe, minimalistic and pythonic RabbitMQ client library
http://rabbitpy.readthedocs.org
BSD 3-Clause "New" or "Revised" License
242 stars 58 forks source link

Non-Blocking Get? #100

Closed fake-name closed 8 years ago

fake-name commented 8 years ago

How can I get an item from the receive queue if present, without blocking if there are no messages available?

As far as I can tell from the docs, basic_get() and basic_consume() are both blocking (despite the misleadingly named nowait parameter for the latter (though we can blame AMQP for that)).

Right now, it seems you have to spin up a thread specifically for the purpose of polling the RX queue, which makes any attempt to design a synchronous system quite horribly messy. Either a try_get() call or a timeout parameter on basic_get() seem like they'd be hugely helpful.

fake-name commented 8 years ago

Looking through the AMQP protocol specs, it looks like the way the AMQP protocol is defined makes it rather difficult to map to a coroutine-like API. A lot of AMQP libraries have implemented some form of timeout on top of AMQP, but they all seem to do it as an additional layer above the AMQP interface, rather then by using a protocol mechanism, probably because the protocol seems to require synchronicity. Annoying.

fake-name commented 8 years ago

Apparently Queue.get() doesn't block. Huh.