hivemq-mqtt-client icon indicating copy to clipboard operation
hivemq-mqtt-client copied to clipboard

Support URIs to connect to a cluster (multiple server)

Open FrVaBe opened this issue 5 years ago • 2 comments

Problem or use case

Some MQTT server - like HiveMQ - support clustering. In a failure szenario a client can connect to one of the still available server instances. It would be great if the (auto re)connect feature of the hivemq-mqtt-client would support this.

The Paho MQTT Client supports this by setting a list of ServerUris. During a (re)connect attempt the library then checks for an availble server of the list and connects.

Preferred solution or suggestions

It would be great if also the MQTT Driver would support this kind of Server/Cluster configuration similar to the Paho MQTT client. There would be no need for a load balancer or somethind else in this case.

Also see: Paho MqttConnectOptions#setServerURIs

FrVaBe avatar Mar 03 '20 21:03 FrVaBe

Hi @FrVaBe This is definitely a feature that we want to integrate in the automatic reconnect feature. In the meantime you can already implement (re)connecting to different broker addresses on your own. The following is just a hint, not a full implementation:

final Mqtt5BlockingClient client = Mqtt5Client.builder()
        .serverHost("broker.hivemq.com")
        .automaticReconnectWithDefaultConfig()
        .addDisconnectedListener(context -> {
            ...
            context.getReconnector()
                    .transportConfig().serverHost("broker2.hivemq.com").applyTransportConfig();
            ...
        })
        .buildBlocking();

SgtSilvio avatar Mar 04 '20 08:03 SgtSilvio

Hey! Is there any update on this feature? Is it still on the roadmap?

nandorsoma avatar Sep 15 '22 12:09 nandorsoma