mosquito / aio-pika

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

using wildcards for accessing/refering multiple queues #528

Open avico78 opened 1 year ago

avico78 commented 1 year ago

My program runs and create many queues, In some case , need to preform multiple queues deletion(or part of maintenance). i couldn't find how i can achieve it with aio_pika .

just an example what i want to accomplish

import aio_pika

async def delete_queues_with_wildcard(pattern):
    connection = await aio_pika.connect_robust("amqp://localhost/")
    channel = await connection.channel()

    async for queue_name, _, _ in channel.queues():
        if queue_name.startswith(pattern):
            queue = await channel.get_queue(queue_name)
            await queue.delete()

    await connection.close()

await delete_queues_with_wildcard("somet_prefix*")

Or having get_queues with support of filtering

        queues = await self.channel.get_queues(filter="customer_*", passive=True)
mosquito commented 1 year ago

AMQP 0.9.x protocol is not provide something like this. The get_queue method is a syntax sugar for declaring queue with a passive flag