Search code examples
javaspringrabbitmqamqpspring-amqp

Load-balanced connection between Spring AMQP java client and nodes of RabbitMQ cluster?


I knew Spring AMQP support failover well, but my question is, how can I load-balanced the connections between consumer side and cluster nodes of RabbitMQ broker?

Any response will be greatly appreciated.

Regards.


Solution

  • According to the RabbitMQ Clustering Guide:

    A client can connect as normal to any node within a cluster. If that node fails and the rest of the cluster survives, then the client should notice the closed connection, and should be able to reconnect to some surviving member of the cluster. Generally, it's not advisable to bake in node hostnames or IP addresses into client applications: this introduces inflexibility and will require client applications to be edited, recompiled and redeployed should the configuration of the cluster change or the number of nodes in the cluster change. Instead, we recommend a more abstracted approach: this could be a dynamic DNS service which has a very short TTL configuration, or a plain TCP load balancer, or some sort of mobile IP achieved with pacemaker or similar technologies. In general, this aspect of managing the connection to nodes within a cluster is beyond the scope of RabbitMQ itself, and we recommend the use of other technologies designed specifically to solve these problems.

    Also see this answer: RabbitMQ client load balancing.

    And a quote from here:

    Create a load balance in front of it and map the backend MQ instance. You can choose either HAProxy or Apache or Nginx or any hardware load balancer you use in your organization.

    If the servers are running in AWS inside a VPC, then choose internal load balancer. Update the application to point to the load balancer end point.

    As you see there is enough info in the Internet on the matter. Right, I didn't provide my opinion here, but it looks like there is no so much difficulties to achieve the desired solution.

    Just configure some load-balancer for Rabbit nodes and use an url from it for the clients.