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)?
The accepted answer is outdated.
From rabbitmq 3.5.0
there's native support for priority queues:
RabbitMQ has priority queue implementation in the core as of version 3.5.0. Any queue can be turned into a priority one using client-provided optional arguments
It's also available as of pika 1.1.0
class pika.spec.BasicProperties(content_type=None, content_encoding=None, headers=None, delivery_mode=None, priority=None, correlation_id=None, reply_to=None, expiration=None, message_id=None, timestamp=None, type=None, user_id=None, app_id=None, cluster_id=None)
The code using this feature might look as follows:
channel.basic_publish(properties=pika.BasicProperties(priority=your_priority),
exchange=...,
routing_key=...,
body=...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With