Pikados is a wrapper around Pika, providing a more asyncio-compatible syntax for channels and connections. An effort is made to keep the syntax close to Pika, but simply provide async functions as many developers expect.
Pikados still uses Pika's AsyncioConnection internally.
Pika is very clever with its usage of callbacks,
allowing its implementation to start a connection with its' #!python __init__ implementation.
import asyncio
from pika import URLParameters, BasicProperties
from pika.spec import Basic
from pikados.channel import AsyncChannel
from pikados.connection import connect, AsyncConnection
url = URLParameters("amqp://guest:guest@localhost:5672/%2F")
def on_message(channel: AsyncChannel, method: Basic.Deliver, properties: BasicProperties, body: bytes):
# Force it to be synchronous (errors will go unseen)
channel.base.basic_ack(method.delivery_tag)
# coro = my_handler(channel, method, properties, body)
# asyncio.get_running_loop().create_task(coro)
# ... await channel.basic_ack(method.delivery_tag)
async def main():
con: AsyncConnection = await connect(url, 'MyApp')
channel = await con.channel()
await channel.basic_qos(prefetch_count=1)
await channel.basic_consume(
'queue',
on_message_callback=on_message,
auto_ack=False,
)
await con.closed.wait()Please install using requirements-docs.txt and run using mkdocs serve.