Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RabbitMQ client load balancing

Tags:

rabbitmq

I am piloting rabbit mq and find it quite good. Looking at the HA page I find that the exchange/queue replication works well.

I am troubled by the fact that I must use a TCP Loadbalancer to balance the load between nodes. Is this correct?

I would like to have 2 nodes in a cluster with a "replicate-all" policy.

I would like and publisher or consumer to be able to connect to all nodes in a round-robin like behavior. Unfortunately the client API only allows setting one host per connection.

Is there any (3rd party maybe?) connection-pool like solution so a publisher publishes and a consumers consumes from all nodes?

like image 346
YaOg Avatar asked May 30 '13 08:05

YaOg


1 Answers

I haven't seen any clients that do connection pooling for AMQP/RabbitMQ. AMQP handles multiple publishers/consumers in a single process with channels and some clients make that easy to use but don't seem to handle automated failover of nodes using a connection pool.

In a cluster there is no need to connect to all nodes in the cluster, consume and publish operations will be correctly routed within the cluster. For consuming trying to manage either single or multiple processes with multiple subscriptions (at least one consume for each connection) has never been the highest priority for me. With multiple processes consuming, each randomly connecting to RabbitMQ, you will be able to maintain availability should one of the RabbitMQ nodes fail.

Publishers in long-lived connections are easily able to reconnect if a failure is detected causing less than a second of disruption, small enough in anything I've worked on to not be a problem.

From a few years of usage I would say that reconnecting to a new host is the simpler problem during a failover with the difficult problem being managing the state within your application in regards to existing AMQP connections. In practice I've just kept a list of the hosts available and pick the next one for each new connection. Any time the connection closes just pick a new host and try again. It does mean a short time where you cannot publish and may be more difficult if you have to constantly make new connections in PHP.

Due to flow control TCP load balancers may be more trouble then they are worth. The TCP back pressure may not make it through the LB causing publishers to publish faster than RabbitMQ can handle. In unscientific tests I've had more issues with RabbitMQ stability when it was behind a load balancer then when clients connected directly.

like image 160
Philip Cristiano Avatar answered Oct 23 '22 00:10

Philip Cristiano