mosquito / aio-pika

AMQP 0.9 client designed for asyncio and humans.
https://aio-pika.readthedocs.org/
Apache License 2.0
1.18k stars 186 forks source link

Async bulk consume #604

Closed kimdre closed 6 months ago

kimdre commented 6 months ago

Hello,

How can I consume messages in bulk from a queue? I would like to consume and write several messages at once to a database in order to reduce the write load on my database when there are many messages in the queue.

At the moment I use the example for asynchronous message processing shown in the docs to insert messages one at a time: https://aio-pika.readthedocs.io/en/latest/quick-start.html#asynchronous-message-processing

mosquito commented 6 months ago

of course you may use aiochannel or asyncio.Queue for aggregating incoming messages, and then call .ack(multiply=True) for confirming multiple of messages receives after triggered by some treshold (queue size or time-based delay or all together).

kimdre commented 6 months ago

Thanks :)