Why put a load balancer in front of a cluster of RabbitMQ nodes (same queue) if every message will be routed to the master node?

Viewed 2535

According to https://groups.google.com/forum/#!topic/rabbitmq-users/vvWAymjDww4, if a queue is mirrored across multiple servers (nodes), it doesn't matter which queue a publisher writes to - RabbitMQ will always forward the message to the master node (the node where the queue was first created).

If this is the case, what's the point of putting a load balancer in front of the nodes if every message will end up being routed to the same node anyway? It seems the master node will always take the entire load.

1 Answers

I'll put an example scenario to make it simple to understand:

  • You have a 2 node cluster, and you have a load balancer on top
  • The client connects to the LB, and gets connected to node1, which is where queue1 resides (master)
  • The queues have HA enabled, therefore queue1 is also replicated on node2
  • node1 fails for some reason, so the new master for queue1 is now node2
  • Client connection drops, and the LB connects him now to node2, so everything is still OK for the client

Basically, it's all about service availability. When you connect to a node, and the queue you're consuming from is not the master, internally RabbitMQ redirects you to the master node, which can end up creating a lot of inter-connections in the cluster.

But if the master node fails, RabbitMQ elects a new node, so having an LB is a great addition there, where the client will reconnect to the LB and it'll get redirected to a working instance. The process for the client is transparent.

Finally, depending on your use-case, you can do clever things to make sure the client always connects to the instance where the master queue resides, but that really depends on your specific requirements.

Related