Sunday, 12 August 2018

Setup RabbitMQ Exchange Federation

Understand Federation in RabbitMQ

RabbitMQ Federation Plugin

#Introduction

RabbitMQ is an open source, light weight, and easy to deploy message broker software, that supports multiple messaging protocol ex AMQP, MQTT, STOMP etc. It can be deployed in cluster, to maintain high availability. When your application is deployed in multiple geographic locations, it becomes very complex to maintain a single cluster for all, as latency comes into the place and increases complexity. Using RabbitMQ Federation Plugin, you can maintain multiple, independent RabbitMQ Clusters and federate messages from one to another.

#Video Tutorial

#Use Cases

  • Collect messages from multiple clusters to a central cluster.
  • Distributing load of one queue to multiple cluster.
  • Migrate data from one cluster to another without downtime.
  • Reduce latency for message consumption.

 #Types of Federation

  1. Exchange Federation:
    With exchange Federation, it is possible to distribute messages to other cluster. It means, messages published on federated exchanges, will be published to local exchange plus downstream server as well. It can be used when, same message you want to consume at multiple places.
  2. Queue Federation:
    Queue federation does intelligent load balancing of messages, it will only send messages to downstream servers, when there will consumers available to consume. It means mesaages are not duplicated. It is useful to distribute load or migration of clusters.

#Terminology

  • Upstream Server: Servers, where messages are getting publish.
  • Downstream Server: Servers, where messages has to be forward.

#Prerequisites

  • Two Rabbitmq Servers/Cluster
  • Management plugin enabled for dashboard
  • Connectivity between both server/Cluster over amqp protocol on port 5672.

#Install Federation Plugin

sudo rabbitmq-plugins enable rabbitmq_federation rabbitmq_federation_management

Restart Rabbitmq Server, for configurations to take effect

sudo systemctl status rabbitmq-server

#Setup Exchange Federation

On both Upstream and Downstream Server:

1. Create a user for federation.


2. Create a vhost in which exchange will be created to federate.


3. Give user access to the above created vhost.


4. Create a exchange that is to be federate in above created vhost.


5. Create a Queue in test_vhost


6. Bind Queue with Exchange



On Downstream Server:

1. Create Federation Upstreams. The URI will be in the format:
     amqp://<federation_username>:<federation_password>@<IP/DNS_of_upstream_server>:5672/<vhost_name>
     In this example: amqp://federation_user:federation_user@X.X.X.X:5672/test_vhost



2. Create Policy for federation.



3. Check Federation Status, it should be running.


Here Exchange federation setup is completed.

#Test Federation

1. Publish message on exchange on Upstream server.


Now, message should present on upstream and downstream queue.


Hurray, its working!



1 comments:

  1. Great Post and Good video.. One question, if you can asnwer, would be really helpful.. In Federated Exchange, if downstream RabbitMQ is down or network outage, then what will happen to messages published on Upstream exchange?

    ReplyDelete

 

Copyright @ 2013 Appychip.

Designed by Appychip & YouTube Channel