RabbitMQ Cluster Migration Strategy
In this blog I will be covering the steps to migrate RabbitMQ Cluster, in the previous blogs I’ve covered the rabbitmq cluster setup followed by the logging and monitoring strategies.
What Needs to be Migrated ?
- Schema Definitions
- Messages
The above data mentioned are usually stored in /var/lib/rabbitmq/data directory.
Pre-Work
In order to do the actual migration, we need to prep our new cluster.
In order to carry out the migration activity we will be needing the following rabbitmq plugins:
- rabbitmq_shovel_management
- rabbitmq_shovel
RabbitMQ Shovel plugin helps in unidirectionally moving of messages from a source to a destination, here the source being the existing cluster and destination being the new cluster we’ve set up.
It would be the best to enable these plugins at the setup time itself given you want to migrate. Incase you miss out on that just run the following command in your rabbitmq server to enable the above plugins.
rabbitmq-plugins enable --offline rabbitmq_shovel_management rabbitmq_shovel
NOTE: Make sure you run this command in all the nodes of your cluster !!
To check if shovel is activated or not you can go to your RabbitMQ Management UI → Click on Admin
You will be able to view Shovel and Shovel Management.
To know more about more features of Shovels click here.
Let’s discuss the HOW..
Step 1: Export the definitions from source cluster
There are 2 ways to do this — via UI or via Command Line
via UI
Go to the Overview Section, scroll down, you’ll find Export Definitions
Click on Download broker definitions.
via Command-Line
rabbitmqctl export_definitions /path/to/definitions.file.json
Step 2: Import Definitions to Destination Cluster
Again similar to export, import can also be done in 2 ways i.e via UI or Command Line, let’s check them one by one..
via UI
Go to the Overview Section, scroll down, you’ll find Import Definitions
Click on Choose file, select your exported definition json file and then click on Upload broker definitions.
The changes will reflect automatically.
via Command-Line
rabbitmqctl import_definitions /path/to/definitions.file.json
Schema Definitions stores the following data:
- Users
- vhosts
- queues
- exchanges
- bindings
- runtime parameters
Step 3: Move messages from source to destination cluster
In your source cluster, go to the UI, select the Queues section
Under the Messages column, there’s a sub-column with the name of Ready, these are basically the messages in the queue that are ready to be read/ack by the consumers.
Sort the Ready sub column to get the number of messages present in the queues, these are the queues from which the messages needs to be migrated to the new destination cluster via shovelling.
Fetch the names of these Queues and click on Admin Section
Go to Shovel Management and enter the data to migrate messages.
We’ve left source URI as it is for it to consider souce as localhost, enter the name of the source and destination queue.
Enter the destination URI in format — amqp://<user>:<pass>@<rabbitmq loadbalancer url for 5672 port>
Click on Add Shovel
🎉🎉 Your messages are migrated.
You can now proceed and shift the traffic to the new cluster.
Checkout my blog on Rabbitmq Setup and RabbitMQ Logging.