Application Scenario
Quorum Queue is a new type of distributed message queue implemented based on the Raft consistency protocol, which is designed for the mirror mode of RabbitMQ. Messages in the quorum queue need to be acknowledged by more than half of the nodes in the cluster before they are written to the queue.
The differences between quorum queue and mirror queue
With mirror queue, when the producer sends a message, the master queue synchronizes the message to the mirror queue. After all mirror queues save the message, the master queue will send an acknowledgment to the producer.
The quorum queue algorithm is an implementation based on the Raft consensus algorithm. The quorum queue consists of one master replica and multiple slave replicas. When the producer sends a message to the master replica, the master replica will synchronize the message with the slave replica. Only when more than half of the replicas save the message, will the master replica send an acknowledgment to the producer. Also, the election of the primary replica requires the consent of more than half of the replicas, which avoids queue metadata inconsistencies in network partitions. So the quorum queue has higher consistency.
Configuration Method
When declaring a queue, set the "x-queue-type" parameter of the queue to "quorum".
The following is a Java example
Map<String, Object> arguments = newHashMap<>();
arguments.put("x-queue-type", "quorum");
channel.queueDeclare("test_quorum_queue", true, false, false, arguments);
Setting the length of the quorum queue
You can limit the length of the quorum queue and the length stored in memory by setting the queue properties.
x-max-length: The maximum number of messages in the quorum queue. If exceeds, the message will be discarded or sent to the dead letter exchange.
x-max-length-bytes: The maximum total message size (bytes) of the quorum queue. If exceeds, the message will be discarded or sent to the dead letter exchange.
x-max-in-memory-length: Limits the maximum number of messages in memory for the quorum queue.
x-max-in-memory-bytes: Limits the maximum total message size (bytes) in memory for the quorum queue.