hirotakaster / MQTT

MQTT for Photon, Spark Core
Other
216 stars 118 forks source link

About client reusability (not really an issue) #30

Closed duffo64 closed 7 years ago

duffo64 commented 7 years ago

Hello @hirotakaster , first of all, great work with this client. It's not clear to me if it is possible to reuse the allocated client object changing ip address.

Use case: I have two independent mqtt clusters, and would switch to cluster2 if cluster1 is unreachable (and vice-versa).

True, I could have two client objects, but the program would be a lot less linear, ram usage would be higher and scalability would be ugly (what if I add another cluster in the mix ? Third client ?). Thank you for your time and efforts

Claudio

hirotakaster commented 7 years ago

I think that's system architecture question. You means like following.

[Photon(MQTT Client)]  <----> [MQTT server 1(health: good): IP Address : X.X.X.X]
                              [MQTT server 2(health: good): IP Address : Y.Y.Y.Y]

when MQTT cluster server1 down because of some problems, MQTT client re-connect to the other MQTT server.

[Photon(MQTT Client)]  <-|       [MQTT server 1(health: down): IP Address : X.X.X.X]
                         |---->  [MQTT server 2(health: good): IP Address : Y.Y.Y.Y]

maybe you can do this using by isConnected() method or tow MQTT object. But if I build same system, I will do following.

[Photon(MQTT Client)]  <-----> LVS(HA and keepalived or heatbeat): Virtual IP : A.A.A.A)
                                [MQTT server 1(health: good): IP Address : X.X.X.X]
                                [MQTT server 2(health: good): IP Address : Y.Y.Y.Y]

LVS check the MQTT server 1,2... health status and switch the connect packet from the client, MQTT client only always connect to the LVS virtual IP A.A.A.A. There is good MQTT client no need to have two MQTT client object(only implements re-connect) and LVS manage some MQTT servers(1,2,3...) health-check and more(load-balance) very easily.

duffo64 commented 7 years ago

Yes, I know thanks. I have already two distinct HAproxies, each of them is balancing 3 mqtt brokers. I simply would avoid clustering HAproxy itself, since I know that one day the whole system will fail (split brain, network partition issues, and so on...) so I would like to manage two instances in code. Moreover, an HAproxy cluster is more difficult to configure, and this system will work with almost untrained personnel, so I would keep things simple.

Thank you, nonetheless.

Claudio