Consumer Priority

What is consumer priority?

When consumers connected to LavinMQ have different priorities, messages are delivered first to those with higher priority and available capacity. Lower-priority consumers receive messages only when higher-priority ones are blocked.

When to use consumer priority?

A typical scenario where consumer priority proves beneficial is resource management. Assign higher priorities to consumers with greater computing power or available resources, enabling efficient handling of critical tasks.


Assign priority to a consumer by setting the x-priority argument in the basic.consume method to an integer value. If no value is specified, the priority is 0. Higher numbers indicate higher priority, with both positive and negative numbers available.

Example: Set the priority on a consumer to 10

import pika

connection = pika.BlockingConnection(pika.URLParameters('host-url'))
channel = connection.channel()

def callback(ch, method, properties, msg):
		print(f"[✅]  { msg }")
		ch.basic_ack(delivery_tag=method.delivery_tag)

channel.basic_consume(
    "test_queue",
    callback,
    auto_ack=False,
    arguments**=**{
      'x-priority':10
    }
)
connection.close()

Consumer capacity

A consumer has capacity when ready to receive a message. It becomes blocked when it can’t, such as when the prefetch limit of unacknowledged messages is reached.
A consumer is either ready or blocked at any given moment.

Multiple consumers with the same priority

If multiple consumers share the same priority, LavinMQ sends messages to the first consumer bound to the queue by default, rather than using a round-robin approach. To ensure fair message distribution among same-priority consumers, set the prefetch value to 1.

Single active consumers and priority consumers

When the single active consumer feature is enabled, priority consumers cannot be used on that queue.


Ready to take the next steps? Here are some things you should keep in mind:

Managed LavinMQ instance on CloudAMQP

LavinMQ has been built with performance and ease of use in mind - we've benchmarked a throughput of about 1,000,000 messages/sec. You can try LavinMQ without any installation hassle by creating a free instance on CloudAMQP. Signing up is a breeze.

Help and feedback

We welcome your feedback and are eager to address any questions you may have about this piece or using LavinMQ. Join our Slack channel to connect with us directly. You can also find LavinMQ on GitHub.