0
0
RabbitMQdevops~7 mins

Shovel and Federation for multi-DC in RabbitMQ - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you have RabbitMQ servers in different data centers, you need a way to move messages between them reliably. Shovel and Federation are tools that help copy or share messages across these separate RabbitMQ setups, so your apps can work together smoothly even if they are far apart.
When you want to copy messages from a queue in one data center to another queue in a different data center automatically.
When you need to share messages between RabbitMQ brokers without merging them into one cluster.
When you want to keep message traffic flowing even if one data center temporarily loses connection.
When you want to reduce network load by only federating specific exchanges or queues instead of all messages.
When you want to build a multi-region RabbitMQ setup for disaster recovery or geographic distribution.
Config File - shovel-federation.conf
shovel-federation.conf
## Shovel configuration example
[
  {rabbitmq_shovel, [
    {shovels, [
      {my-shovel, [
        {sources, [{broker, "amqp://user:password@source-dc-host"}]},
        {destinations, [{broker, "amqp://user:password@target-dc-host"}]},
        {queue, "source-queue"},
        {ack_mode, on_confirm},
        {publish_properties, [persistent]},
        {reconnect_delay, 5}
      ]}
    ]}
  ]},
  {rabbitmq_federation, [
    {exchanges, [
      {"federated-exchange", [
        {upstream, [{uri, "amqp://user:password@remote-dc-host"}]}
      ]}
    ]}
  ]}
].

This config file sets up two things:

  • Shovel: It copies messages from a queue named source-queue on one RabbitMQ server to another server automatically. It reconnects if the connection drops.
  • Federation: It links an exchange called federated-exchange to a remote RabbitMQ server, so messages published there are shared across data centers.
Commands
This command creates a shovel named 'my-shovel' that copies messages from 'source-queue' on the source server to 'target-queue' on the target server. It ensures messages are confirmed and persistent, and it will try reconnecting every 5 seconds if the connection drops.
Terminal
rabbitmqctl set_parameter shovel my-shovel '{"src-uri":"amqp://user:password@source-dc-host","src-queue":"source-queue","dest-uri":"amqp://user:password@target-dc-host","dest-queue":"target-queue","ack-mode":"on-confirm","publish-properties":["persistent"],"reconnect-delay":5}'
Expected OutputExpected
Setting parameter "my-shovel" for component "shovel" ...
This command defines a federation upstream named 'my-upstream' that points to the remote RabbitMQ server where messages will be fetched from.
Terminal
rabbitmqctl set_parameter federation-upstream my-upstream '{"uri":"amqp://user:password@remote-dc-host"}'
Expected OutputExpected
Setting parameter "my-upstream" for component "federation-upstream" ...
This command creates a federation upstream set named 'my-upstream-set' that includes the upstream 'my-upstream'. This groups upstreams for easier management.
Terminal
rabbitmqctl set_parameter federation-upstream-set my-upstream-set '{"upstreams":["my-upstream"]}'
Expected OutputExpected
Setting parameter "my-upstream-set" for component "federation-upstream-set" ...
This command applies federation to the exchange named 'federated-exchange', linking it to the upstream set so it receives messages from the remote server.
Terminal
rabbitmqctl set_parameter federation-exchange federated-exchange '{"upstream-set":"my-upstream-set"}'
Expected OutputExpected
Setting parameter "federated-exchange" for component "federation-exchange" ...
This command lists all current shovel and federation parameters to verify the setup is applied correctly.
Terminal
rabbitmqctl list_parameters
Expected OutputExpected
shovel my-shovel {"src-uri":"amqp://user:password@source-dc-host","src-queue":"source-queue","dest-uri":"amqp://user:password@target-dc-host","dest-queue":"target-queue","ack-mode":"on-confirm","publish-properties":["persistent"],"reconnect-delay":5} federation-upstream my-upstream {"uri":"amqp://user:password@remote-dc-host"} federation-upstream-set my-upstream-set {"upstreams":["my-upstream"]} federation-exchange federated-exchange {"upstream-set":"my-upstream-set"}
Key Concept

If you remember nothing else from this pattern, remember: Shovel copies messages between queues across servers, while Federation shares messages at the exchange level to connect RabbitMQ brokers in different data centers.

Common Mistakes
Using incorrect URIs with wrong usernames or passwords in shovel or federation parameters.
The connection will fail and messages won't be transferred between servers.
Double-check and test the AMQP URIs with correct credentials and hostnames before applying parameters.
Not setting 'ack-mode' to 'on-confirm' in shovel configuration.
Messages might be lost if the shovel assumes delivery without confirmation.
Always set 'ack-mode' to 'on-confirm' to ensure messages are safely copied.
Applying federation to exchanges that do not exist or have no bindings.
No messages will flow because the exchange is inactive or unused.
Create and bind exchanges properly before federating them.
Summary
Use 'rabbitmqctl set_parameter' commands to configure shovels and federation upstreams and exchanges.
Shovel moves messages queue-to-queue across RabbitMQ servers with confirmation and persistence.
Federation links exchanges across servers to share messages without merging clusters.
Verify your setup by listing parameters and checking connectivity between data centers.