Quorum Queues
Scenario
Quorum queues provide the queue replication capability to ensure high data availability and security. Quorum queues can be used to replicate queue data between RabbitMQ nodes, ensuring that queues can still run when a node breaks down.
Quorum queues can be used in scenarios where queues exist for a long time and there are high requirements on queue fault tolerance and data security and low requirements on latency and queue features. Quorum queues are not recommended if a large number of messages may be stacked, because write amplification significantly increases disk usage.
Messages in quorum queues are preferentially stored in the memory. You are advised to limit the queue length and memory usage of quorum queues. When the number of stacked messages exceeds the threshold, the messages are written to the disk to avoid high memory watermark.
For more information about quorum queues, see Quorum Queues.
![](https://support.huaweicloud.com/eu/usermanual-rabbitmq/public_sys-resources/notice_3.0-en-us.png)
Quorum queues are available only in RabbitMQ 3.8.35.
Comparing Quorum Queues and Mirrored Queues
Quorum queues are introduced in RabbitMQ 3.8 to address the technical limitations of mirrored queues. Quorum queues have similar functions as mirrored queues and provide high-availability queues for RabbitMQ.
Mirrored queues are slow at replicating messages.
- A mirrored queue has a queue leader and many mirrors. When a producer sends a message to the queue leader, the leader replicates the message to the mirrors, and sends back confirmation to the producer only after all mirrors have saved the message.
- If a node in a RabbitMQ cluster goes offline due to a fault, all data in the mirrors stored on the node will be lost after the fault is rectified and the node goes online again. In this case, O&M personnel need to determine whether to replica data from the queue leader to the mirrors. If they choose not to replicate data, messages may be lost. If they choose to replicate data, the queue is blocked during replication and no operation can be performed on the queue. When a large number of messages are stacked, the queue will be unavailable for several minutes, hours, or even longer.
Quorum queues can solve these problems.
- Quorum queues are based on a variant of the Raft consensus algorithm. They deliver a higher message throughput. A quorum queue has a primary replica (queue leader) and many followers. When a producer sends a message to the leader, the leader replicates the message to the followers, and sends back confirmation to the producer only after half of the followers have saved the message. This means that a small number of slow followers do not affect the performance of the entire queue. Similarly, the election of the leader requires the consent of more than half of the followers, which prevents the queue from having two leaders in the event of network partitioning. Therefore, quorum queues attach more importance to consistency than availability.
- After a node in a RabbitMQ cluster goes online after recovering from a fault, the data stored on the node will not be lost. The queue leader directly replicates messages from the position where the followers were interrupted. The replication process is non-blocking, and the entire queue is not affected by the addition of new followers.
Compared with mirrored queues, quorum queues have fewer features, as shown in Table 1. Quorum queues consume more memory and disk space.
Feature |
Mirrored Queues |
Quorum Queues |
---|---|---|
Non-durable queues |
Supported |
Not supported |
Exclusive queues |
Supported |
Not supported |
Message persistence |
Per message |
Always |
Queue rebalancing |
Automatic |
Manual |
Message TTL |
Supported |
Not supported |
Queue TTL |
Supported |
Supported |
Queue length limit |
Supported |
Supported (except x-overflow: reject-publish-dlx) |
Lazy queues |
Supported |
Supported after the queue length is limited |
Message priority |
Supported |
Not supported |
Consumption priority |
Supported |
Supported |
Dead letter exchanges |
Supported |
Supported |
Dynamic policy |
Supported |
Supported |
Poison message (let consumers consume infinitely) handling |
Not supported |
Supported |
Global QoS prefetch |
Supported |
Not supported |
Configuration
When declaring a queue, set the x-queue-type queue argument to quorum. This argument can be set only during queue declaration and cannot be set by using a policy.
The default replication factor of a quorum queue is five.
- The following example shows how to configure a quorum queue on a Java client.
ConnectionFactory factory = newConnectionFactory(); factory.setRequestedHeartbeat(30); factory.setHost(HOST); factory.setPort(PORT); factory.setUsername(USERNAME); factory.setPassword(PASSWORD); finalConnection connection = factory.newConnection(); finalChannel channel = connection.createChannel(); // Create the queue parameter map. Map<String, Object> arguments = newHashMap<>(); arguments.put("x-queue-type", "quorum"); // Declare the quorum queue. channel.queueDeclare("test-quorum-queue", true, false, false, arguments);
- The following example shows how to configure a quorum queue on the RabbitMQ management UI.
Figure 1 Configuring a quorum queue
After the configuration is complete, check whether the queue type is quorum on the Queues page, as shown in Figure 2. In the Node column, +2 indicates that the queue has two replicas. Blue indicates that the two replicas have been synchronized. Red indicates that some messages have not been replicated.
On the Queues page, click the name of the desired queue. Check the node where the leader of this quorum queue resides and the node where active followers reside.
Figure 3 Queue details page
Configuring the Quorum Queue Length
You can configure a policy or queue attributes to limit the length of a quorum queue and the length that can be stored in the memory.
- x-max-length: maximum number of messages in the quorum queue. If this limit is exceeded, excess messages will be discarded or sent to the dead letter exchange.
- x-max-length-bytes: maximum size (in bytes) of messages in the quorum queue. If this limit is exceeded, excess messages will be discarded or sent to the dead letter exchange.
- x-max-in-memory-length: maximum number of messages of the quorum queue that can be stored in memory.
- x-max-in-memory-bytes: maximum size (in bytes) of messages of the quorum queue that can be stored in memory.
The following describes how to limit the length of a quorum queue stored in the memory by configuring a policy or the queue attribute.
- By using a policy (recommended)
Figure 4 Using a policy to set x-max-in-memory-bytes
- By configuring the queue argument
Figure 5 Setting x-max-in-memory-length in the queue argument
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.