← Back to Knowledge Base
Software DevelopmentJuly 31, 20171 min read

RabbitMQ Cluster With Terraform On AWS

Creating RabbitMQ cluster is tricky. It is easy to do manually and hard if you’d like to automate it.

Creating RabbitMQ cluster is tricky. It is easy to do manually and hard if you’d like to automate it.

TL;DR Use this Terraform configuration to create RabbitMQ cluster in less than 5 minutes.

The simplest cluster requires 2 nodes and a load balancer. In AWS we are going to use ELB as a load balancer and put nodes in Auto Scaling group, so that if a node goes down (or became unhealthy) it will be replaced by a new one.

Our setup will be:

rabbitmq

                                                         

Using Terraform we can create Launch Configuration, Auto Scaling group and ELB. This is our ELB configuration:

What about nodes ? We use cloud-init to initialize a node and in there we configure RabbitMQ to run in Docker.

To find out what are the other nodes in the cluster we prepared a bash script that query nodes in our Auto Scaling group:

And then a script to join to these nodes:

The tricky part here is that to join a cluster, you have to stop the node first. So there is a chance that other node could also be stopped as well. To mitigate this problem we set sleep for some random amount of seconds before stopping the server Also, in case of errors, we perform sane amount of retries.

Using this Terraform configuration we successfully deployed many RabbitMQ clusters with up to 4 nodes.

Leave a comment if you find this useful or a question in case of troubles. Cheers!

About author

Konrad Rotkiewicz

CEO


Konrad has 6 years of strong background in Embedded & Networking programming, as well as experience leading multiple teams for UK and US customers, which has laid the foundations for him to become a natural Technology leader. A man obsessed with continuous improvements, Konrad is never satisfied with his results.

About us
Portrait of Konrad Rotkiewicz

MedTech insights delivered

Real case learnings, product decisions, and technical insights from building healthcare software. No marketing fluff.

Mobile app screen — Annual exam for ECG machine
Featured case study

Five years. One team. From 1 hospital to 200.

Hospital staff were reporting issues on paper, by phone, or not at all. No single platform, no visibility, no way to track resolution. We built one and we're still running it five years later.

200+

Hospitals internationally

10,000

Active users

99.9%

Uptime

Additional learning

Explore related topics in our
Knowledge Base

Browse all articles
ULAM LABS senior engineering team

Let's see if we're a good fit

No lengthy onboarding, no big commitment upfront. Book a call and we'll tell you within a week if we're the right fit.