Sakib Sami' Blog

Newbie programmer, Java fan, Rosogolla lover, Mom's little kid.

How to : Setup MQTT cluster with HAProxy

What's up good people ? Hope well.
Ok, Few days back was trying to setup MQTT cluster server and choose HAProxy to use as load balancer.
This is a short guide how I managed everything.

I have 3 server from digital ocean (vps service provider).
Assume they are :

  1. (
  2. (
  3. ( is load balancer where I setup HAProxy. is first server of mqtt and is second server of mqtt.

I used emqttd as MQTT broker. Download link

After emqttd setup on node1 and node2 to enable clustering enter into change hostname to

change in etc/emq.conf as : =  

Do same for node2 but here with

Now from node1 or node2 execute

emqttd_ctl cluster join  
# Assuming you are on node1

now to check cluster status execute,

emqttd_ctl cluster status  

Result should be,


Now time to setup HAProxy for load balancing,
Enter into and

sudo apt-get install haproxy  

To enable HAProxy change in /etc/default/haproxy to


change in /etc/haproxy/haproxy.cfg

log     global  
mode    tcp  
option  tcplog  

And add

frontend mqtt  
    default_backend mqtt

backend mqtt  
    mode tcp
    balance roundrobin
    server node1 check
    server node2 check

frontend mqtt_dashboard  
    default_backend mqtt_dashboard

backend mqtt_dashboard  
    mode http
    balance roundrobin
    server node1 check
    server node2 check

And you are done.
Now browse
Mqtt URL : tcp://
you will see server are swapping.
Emqttd dashboard default
user : admin, pass : public

C/C++ Pointer

Todays blog post is on C/C++ pointer. Pointer allows you to access memory address directly. Pointer…

c, c++, pointer, memory, programming