Ping RabbitMq cluster when load-balanced by Haproxy

Shrey Agarwal
1 min readNov 17, 2016

--

We use RabbitMq for a lot of operations. It forms bus/queueing system/pub-sub base for a lot of sub-systems. Mostly all rabbitMq installations are in cluster mode , and we use Haproxy to loadbalancer / HA.

Google for rabbitmq timeout haproxy , and you will find a lot of issues related to rabbitmq connections timing out when using with Haproxy. Most of solutions ask you to change haproxy config which do not work. Alternate solutions are changing kernel limits on TCP keepalive, which I believe should be the last resort.

Now, haproxy demands that some packets be sent on the connection which forcefully keeps the connection open. What can be those packets ? RabbitMq heartbeat does not do the trick ( still figuring out why). We need some more robust ping mechanism from client to server.

RabbitMq protocol ( AMQP) does not have Ping. We came out with solution where we open a channel every x seconds and close it immediately. Channels are way to multiplex multiple operations over a single connection and very lightweight. Its holding out so far. You can find the implementation here

Haproxy config

listen rabbitmq 0.0.0.0:5672
mode tcp
log global
retries 3
timeout client 3h
timeout server 3h
option clitcpka
option tcplog
default_backend rmqbackend
backend rmqbackend
mode tcp
balance leastconn
server x 10.0.0.2:5672 check
server y 10.0.0.3:5672 check
server z 10.0.0.4:5672 check

--

--