user666
user666

Reputation: 2013

How to use RabbitMQ quorum queue for data replication

In RabbitMQ documentation, it is mentioned that:

All data/state required for the operation of a RabbitMQ broker is replicated across all nodes. An exception to this are message queues, which by default reside on one node, though they are visible and reachable from all nodes. To replicate queues across nodes in a cluster, use a queue type that supports replication. This topic is covered in the Quorum Queues guide.

If we are using springboot amqp classic queue and we need to start using a cluster of RabbitMQ where data is replicated across nodes for a lowest risk of data loss, what changes needs to be done to the code to start using a quorum queue?

Upvotes: 3

Views: 6518

Answers (1)

user666
user666

Reputation: 2013

When defining the queue, by default, the type is classic queue, to choose the quorum type instead, just add the type of queue as argument:

@Bean
public Queue eventsQueue() {
    Map<String, Object> args = new HashMap<>();
    args.put("x-queue-type", "quorum");
    return new Queue(queueName, true, false, false, args);
}

In addition to the above, make sure you point your spring boot rabbit mq to the cluster not to one node. This can be done by changing spring.rabbitmq.host configuration in application.properties to spring.rabbitmq.addresses=[comma separated ip:port]

A Classic Queue has a master running somewhere on a node in the cluster, while the mirrors run on other nodes. This works the very same way for Quorum Queues, whereby the leader, by default, runs on the node the client application that created it was connected to, and followers are created on the rest of the nodes in the cluster. In the past, replication of queues was specified by using policies in conjunction with Classic Queues. Quorum queues are created differently, but should be compatible with all client applications which allow you to provide arguments when declaring a queue. The x-queue-type argument needs to be provided with the value quorum when creating the queue.

Upvotes: 6

Related Questions