Skip to content

RabbitMQ federation across sites — when shovel is wrong and federation is right

Multi-site RabbitMQ with the federation plugin — upstreams, policies, the difference from shovel, and the network and lag realities of running across two regions.

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

  1. Enable federation on every node of both clusters. The plugin ships with RabbitMQ — no separate package:

    sudo rabbitmq-plugins enable rabbitmq_federation rabbitmq_federation_management

    The _management half adds federation status to the web UI.

  2. 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.

  3. 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.

  4. 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-set of all matches every upstream you have declared. For per-link control, name an upstream-set you have built explicitly.

  5. 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, ...

    status should be running. Anything else (starting, connecting, error) needs investigation — usually credentials, network, or a missing exchange on the upstream.

  6. Wire monitoring. The Prometheus endpoint exposes federation metrics:

    rabbitmq_federation_link_status
    rabbitmq_federation_unconfirmed_messages
    rabbitmq_federation_inflight_messages

    Alert on rabbitmq_federation_link_status != 1 for more than 60 seconds. Federation links that flap silently can backfill huge volumes once they reconnect — you want to know before the WAN saturates.

  7. 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-confirm waits for the downstream publish confirm before acking the upstream — slower, but guarantees no message loss on downstream broker failure. max-hops: 1 prevents 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 — set expires so 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_links after any plugin work.
  • TLS for federation is non-optional across the public internet; the upstream URI takes amqps:// plus a ssl_options parameter 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-hops parameter 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.