0
0
RabbitmqConceptBeginner · 3 min read

What is Federation in RabbitMQ: Explanation and Example

In RabbitMQ, federation is a way to connect multiple brokers so they can share messages without full clustering. It allows queues or exchanges on one broker to receive messages from another broker, enabling distributed messaging across different networks or data centers.
⚙️

How It Works

Federation in RabbitMQ works like a bridge between separate message brokers. Imagine two post offices in different cities that want to share mail without merging into one big office. Federation lets them forward mail (messages) to each other while keeping their own operations independent.

Technically, federation uses special plugins that create links between exchanges or queues on different RabbitMQ servers. These links pull messages from the source broker and deliver them to the destination broker. This happens over the network, so brokers can be in different locations or cloud environments.

This setup is useful when you want to share messages but avoid the complexity and tight coupling of clustering. Federation is more flexible and works well across firewalls or slow connections.

💻

Example

This example shows how to configure federation for an exchange named logs on a source broker to be federated to a destination broker.

bash
## On the destination broker's rabbitmq.conf
federation-upstream my-upstream {
  uri = "amqp://source_user:source_password@source_host"
  expires = 3600000
}

federation-upstream-set my-upstream-set {
  upstreams = [my-upstream]
}

## Declare a policy to federate the 'logs' exchange
policy federate-logs "^logs$" {
  federation-upstream-set = my-upstream-set
  apply-to = exchanges
  priority = 1
}
Output
Policy 'federate-logs' applied to exchange 'logs' to pull messages from source broker
🎯

When to Use

Use federation when you need to share messages between RabbitMQ brokers that are geographically separated or run in different networks. It is ideal for:

  • Distributing workload across data centers without full clustering.
  • Connecting cloud and on-premises RabbitMQ servers.
  • Sharing messages securely across firewalls.
  • Scaling message delivery without tight coupling.

Federation is not a replacement for clustering but a complementary approach for flexible, loosely connected messaging systems.

Key Points

  • Federation links exchanges or queues between separate RabbitMQ brokers.
  • It enables message sharing without full cluster setup.
  • Works well across networks, firewalls, and different locations.
  • Configured via policies and upstream definitions.
  • Useful for distributed, scalable messaging architectures.

Key Takeaways

Federation connects separate RabbitMQ brokers to share messages without clustering.
It uses upstreams and policies to link exchanges or queues across networks.
Ideal for distributed systems needing loose coupling and cross-network communication.
Federation is configured on the destination broker to pull messages from the source.
It helps scale and distribute messaging across data centers or cloud environments.