Learn Labs
Operations

Clustering

How nodes cluster, Khepri, network partitions, maintenance mode, and upgrades

A RabbitMQ cluster is a set of nodes that share metadata (users, vhosts, exchanges, bindings, queue definitions, policies) and route messages to each other. Message data is not shared automatically: a queue's messages live on its own members, which is what quorum queues and streams replicate.

Forming the cluster

This stack uses classic config peer discovery: each node has the full list in rabbitmq.conf and joins the others at first boot. Other backends discover peers from DNS, Kubernetes, Consul, or AWS. Manual clustering also works:

# join rabbit-3 to rabbit-1's cluster by hand (wipes rabbit-3's data)
docker exec rabbit-3 rabbitmqctl stop_app
docker exec rabbit-3 rabbitmqctl reset
docker exec rabbit-3 rabbitmqctl join_cluster rabbit@rabbit-1
docker exec rabbit-3 rabbitmqctl start_app

Requirements, all of which the compose file handles: every node has the same Erlang cookie, a stable hostname, and can reach the others on the Erlang distribution port (25672) and the inter-node ports.

Khepri: Raft for metadata

RabbitMQ 4 stores cluster metadata in Khepri, a Raft-based store (the khepri_db feature flag is enabled on this cluster). Before Khepri, metadata lived in Mnesia, which could disagree with itself after a network partition and needed a cluster_partition_handling strategy to recover. With Khepri, metadata changes need a majority of nodes, just like quorum queues:

  • A node cut off in a minority can't change metadata (declare queues, add bindings) until it rejoins.
  • The majority side keeps operating.
  • When the partition heals, the minority catches up from the Raft log. There's nothing to reconcile by hand.

Where queues live

Clients can connect to any node, but each queue has a leader on one node. A consumer connected to rabbit-1 reading a queue led by rabbit-2 works fine, with an extra network hop inside the cluster.

queue_leader_locator = balanced(config) place new queue leaders on the least-loaded nodex-queue-leader-locator: client-local(argument) or put the leader on the node the client is connected torabbitmq-queues rebalance quorumspread existing leaders evenly

Maintenance and rolling restarts

rabbitmq-upgrade await_online_quorum_plus_onewait until stopping this node won't cost any queue its majorityrabbitmq-upgrade drainmaintenance mode: close clients, move leaders away... restart or upgrade the node ...rabbitmq-upgrade reviveback into servicerabbitmq-diagnostics check_if_node_is_quorum_critical

A safe rolling upgrade: for each node, check it's not quorum-critical, drain it, upgrade and restart it, revive it, wait for every quorum queue to have all members again, then move on. Upgrades between minor versions are done this way with no downtime; check the release notes for feature flags to enable afterwards (rabbitmqctl enable_feature_flag all).

Clusters across data centres

Don't stretch one cluster across regions: Raft needs low latency between members, and every write waits for a majority. For multiple sites, run a cluster per site and move messages between them with Shovel (copies messages from a queue to an exchange elsewhere) or Federation (an exchange or queue that pulls from an upstream cluster).

Lab

  1. Run rabbitmqctl cluster_status and find the running nodes, feature flags, and listeners.
  2. Drain rabbit-2, list queues with their types and leaders, and find what's still led by rabbit-2. Revive it.
  3. Stop rabbit-3 and rabbit-2. Try to declare a queue from a client connected to rabbit-1. Start them again.
  4. Run rabbitmq-upgrade await_online_quorum_plus_one with all nodes up, and again with one down.

On this page