Polyconseil / aioamqp

AMQP implementation using asyncio
Other
280 stars 88 forks source link

Introduce a new api to consume message from Rabbit. #218

Open dzen opened 4 years ago

dzen commented 4 years ago

The goal is to get rid of the callback, which is imho a non-sense in an asyncio context.

the new Channel::consume method now returns a MessageQueue objects which can be iterated using async for.

This object allows us to ease the API:

    x = channel.consume(queue_name='hello')
    await x.qos(prefetch_size=0, prefetch_count=1)
    async with x as consumer:
        async for message in consumer:
            body, envelope, properties = message
            await channel.basic_client_ack(delivery_tag=envelope.delivery_tag)