title: Configure HAProxy for rabbitmq
body: <p>I want to use HAProxy as a load balancer. I want to put two rabbitmq server behind haproxy. Both the rabbitmq server are on different instance of EC2. I have configure HAProxy server by following <a href="http://www.joshdevins.net/2010/04/16/rabbitmq-ha-testing-with-haproxy/" rel="nofollow noreferrer">this reference</a>. I works but the problem is messages are not published in roundrobin pattern. Messages are publish only on one server. Is there any different configuration for my requirement?</p>
  
  <p>My configureation in /etc/haproxy/haproxy.cfg</p>
  
  <pre><code>listen rabbitmq 0.0.0.0:5672
       mode    tcp
       stats   enable
       balance roundrobin
      option tcplog
      no  option clitcpka
      no option srvtcpka
       server  rabbit01 46.XX.XX.XX:5672 check
       server  rabbit02 176.XX.XX.XX:5672 check
  listen  web-service *:80
            mode    http
           balance roundrobin
          option httpchk HEAD / HTTP/1.0
           option httpclose
          option forwardfor
          option httpchk OPTIONS /health_check.html
          stats enable
          stats refresh 10s
          stats hide-version
          stats scope   .
          stats uri     /lb?stats
          stats realm   LB2\ Statistics
          stats auth    admin:Adm1nn
  </code></pre>
  
  <p><b>Update:</b></p>
  
  <p>I have made some R&amp;D on this and found that HAProxy is round robin the connection on the rabbitmq server. for ex: if i request for 10 connections then it will round robin the 10 connection over my 2 rabbitmq servers and publish the message. </p>
  
  <p>But the problem is I want to round robin the messages, not connection it should be manage by HAProxy server. i.e if i send 1000 msg at a time to HAProxy then 500 msg should go to rabbit server1 and 500 msg should go to rabbit server2. What should be the configuration that i have to follow?</p>
  
  <p><b>Update:</b></p>
  
  <p>I have also test with leastconn in balancing but HAProxy behavior in unexpected. I have posted that question on <a href="https://serverfault.com/questions/388801/unexpected-behaviour-when-dynamically-add-node-in-haproxy-server">serverfault.com</a> </p>