K
K
KirSupi2021-11-04 01:59:30
Python
KirSupi, 2021-11-04 01:59:30

How to set tickrate in aio-pika (asyncio)?

There is a code

from aio_pika import *
import asyncio


loop = asyncio.get_event_loop()


async def on_message(message: IncomingMessage):
    print("Message body is: %r" % message.body)


async def listen():
    connection = await connect("amqp://guest:[email protected]/", loop=loop)
    channel = await connection.channel()
    queue = await channel.declare_queue("my_queue", durable=False)
    await queue.consume(on_message, no_ack=True)


if __name__ == '__main__':
    loop.create_task(listen())
    loop.run_forever()


It is necessary to make a certain frequency of listening, i.e., for example, so that on_message works, takes from the queue and displays 1 message per second (if it is there, of course), but not more often

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question