Two RabbitMQ clusters in two regions, and a directive to “make them talk.” This article is the federation install we run when the topology calls for selective, declarative replication of exchanges or queues across WAN links — not the full cluster-stretch fantasy that breaks the moment latency exceeds 50 ms. We cover where federation fits, where the shovel plugin is the better tool, and the operational gotchas that show up at three months, not three days.
How to verify
Before installing anything, confirm what is already enabled on each side:
sudo rabbitmq-plugins list | grep -E 'federation|shovel'
sudo rabbitmqctl list_policies
sudo rabbitmqctl status | grep -E 'RabbitMQ version'
# from cluster A, confirm AMQP reachability to cluster B
nc -vz cluster-b.example.net 5672
Federation rides over standard AMQP (5672 or 5671 with TLS), not the cluster protocol — that is the whole point. If the AMQP port is reachable between sites and credentials are agreed, federation is ready to install.
What’s happening
A RabbitMQ federation link is a downstream node connecting to an upstream broker as a normal AMQP client, declaring a queue or consuming from an exchange, and re-publishing what it receives into the local broker. Two flavors:
- Federated exchange. The downstream declares a queue bound to the upstream exchange with the routing topology you specify. Messages published to the upstream exchange are forwarded to the downstream and re-published onto the local copy of the exchange. Local consumers see them as local messages.
- Federated queue. The downstream declares a queue locally and only pulls messages from the upstream queue when there is local consumer demand. Messages are moved, not copied — once a downstream consumer takes a message, it is gone from the upstream queue.
Federation is per-link, asynchronous, and survives WAN outages. A federation link in connecting state buffers nothing (it has not connected yet), but once running it tolerates drops; reconnection is automatic with exponential backoff. Messages already in the upstream queue stay there until the link comes back.
The other multi-site tool is the shovel plugin, which is closer to a managed AMQP-to-AMQP forwarder. Shovel pulls from one queue and publishes to one destination (queue or exchange, same or different broker). Use shovel when you need one-off movement (drain a queue, migrate from one cluster to another, copy from one vhost to another). Use federation when you need ongoing multi-site topology where exchanges or queues stay in sync.
What federation is not: a cluster across WAN. Clustering replicates Mnesia synchronously and demands sub-millisecond, lossless links. Across a 30 ms WAN your cluster will partition during normal jitter and you will spend Saturdays running rabbitmqctl cluster_status to clean up. Federation does the loose-coupling job instead.
The procedure
-
Enable federation on every node of both clusters. The plugin ships with RabbitMQ — no separate package:
sudo rabbitmq-plugins enable rabbitmq_federation rabbitmq_federation_managementThe
_managementhalf adds federation status to the web UI. -
Create a federation user on the upstream cluster. Federation links authenticate as a normal AMQP client; create a least-privilege user, not an admin:
# on cluster A (the upstream) sudo rabbitmqctl add_user fed-user "$(openssl rand -base64 24)" sudo rabbitmqctl set_permissions -p / fed-user "" "^federation.*" "^orders|^events"The configure regex restricts what fed-user can declare; the read regex restricts the exchanges or queues it can subscribe to.
-
Declare the upstream on the downstream cluster. This is a runtime declaration, not a config file — it lives in Mnesia and is replicated across the downstream cluster:
# on cluster B (the downstream) sudo rabbitmqctl set_parameter federation-upstream \ site-a-orders '{"uri":"amqps://fed-user:PASS@cluster-a.example.net:5671","expires":3600000}'expires(ms) is the TTL of the federation queue declared on the upstream — set it long enough that a downstream restart does not drop unforwarded messages. -
Apply a federation policy. The policy is what links the upstream to local exchanges or queues; the regex selects what to federate:
sudo rabbitmqctl set_policy --apply-to exchanges \ federate-orders "^orders\." '{"federation-upstream-set":"all"}'federation-upstream-setofallmatches every upstream you have declared. For per-link control, name an upstream-set you have built explicitly. -
Verify the link is running. The management UI shows a Federation tab once links exist; from CLI:
sudo rabbitmqctl list_federation_links # name, vhost, type, uri, status, exchange|queue, upstream, ...statusshould berunning. Anything else (starting,connecting,error) needs investigation — usually credentials, network, or a missing exchange on the upstream. -
Wire monitoring. The Prometheus endpoint exposes federation metrics:
rabbitmq_federation_link_status rabbitmq_federation_unconfirmed_messages rabbitmq_federation_inflight_messagesAlert on
rabbitmq_federation_link_status != 1for more than 60 seconds. Federation links that flap silently can backfill huge volumes once they reconnect — you want to know before the WAN saturates. -
Configure prefetch and ack-mode for the link. The upstream parameter accepts these knobs:
{ "uri": "amqps://fed-user:PASS@cluster-a.example.net:5671", "prefetch-count": 1000, "ack-mode": "on-confirm", "max-hops": 1, "expires": 3600000 }ack-mode: on-confirmwaits for the downstream publish confirm before acking the upstream — slower, but guarantees no message loss on downstream broker failure.max-hops: 1prevents loops when both sites federate to each other.
Operational notes
- Federation queue names on the upstream follow the pattern
federation: <downstream-name> -> <exchange>. They are real queues that consume disk and memory — setexpiresso they self-clean if the downstream disappears for good. - Federation links survive cluster restarts, but a plugin disable/enable cycle drops them; re-enabling does not auto-recreate links if the policy is still in place — check
list_federation_linksafter any plugin work. - TLS for federation is non-optional across the public internet; the upstream URI takes
amqps://plus assl_optionsparameter for client certs if mutual TLS is required. - Time skew between sites by more than a few seconds confuses TTL-based queues and message timestamps; sync clocks via chrony or NTP on every broker.
- The
max-hopsparameter is the only thing preventing routing loops in bi-directional federation; set it to 1 unless you have a documented multi-hop topology.
Stack Harbor stands up federated RabbitMQ topologies for clients with multi-region application footprints — primary in one region, read replicas or DR fan-out in another, with federation links that drop and reconnect cleanly across WAN flaps and have an alerting story that does not depend on someone watching a dashboard. This is the kind of design and operating model covered by our Multi-region environments practice.