benjamin-hodgson / asynqp

An AMQP library for asyncio
MIT License
84 stars 29 forks source link

Queue get as a blocking method #89

Closed pkolchanov closed 7 years ago

pkolchanov commented 8 years ago

Why get() method returns None if there were no messages on the queue instead of wait them?

tvoinarovskyi commented 8 years ago

Because it implements the sync API for queue polling. It's part of AMQP spec, see https://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.get For async AMQP API you can use the queue.consume to register a callback for messages and use it to get somehow an API like you want:

from asyncio import Queue

async def process_asynqp_queue(asynqp_queue):
     msg_buffer = Queue()
     await asynqp_queue.consume(msg_buffer.put_nowait)
     while True:
         msg = await msg_buffer.get()
tvoinarovskyi commented 8 years ago

Of course a proper implementation with all error handling and reconnects is more troublesome thou...