Search code examples
pythonrabbitmqpriority-queueamqppika

How to Implement Priority Queues in RabbitMQ/pika


I am looking to implement a priority queue with RabbitMQ. The mailing list recommends to use multiple queues, each queue representing a different priority level.

My question is, how do you poll multiple queues in some prioritized order using pika (or possibly some other python library)?


Solution

  • I don't think there is a way to do it naively at the consumer level with pika, as all consumers by default have the same priority.

    What I might do to solve the problem would be to have the two queues as suggested on the mailing list, each queue with its own consumer. In the consumer callback for each consumer instead of dealing with the message directly I would put it into a priority queue, then call a function that reads the highest priority message from the queue and handles it.

    Another question with a similar response.