aries aries - 29 days ago 18
Java Question

Eclipse paho connecting to distributed broker

I am using Apache Artemis as my mqtt broker. I have an Artemis cluster which is configured in Master-Slave fashion. When the Master server fails, the backup server takes over and the client has to connect to the slave server. Master and slave are having different IP.

Is there an option to specify multiple connect url (address of master and slave) while creating a MqttClient object in eclipse paho?

Something like

MqttClient cl = new MqttClient("LIST OF IPs", "Publisher", new
MemoryPersistence());


instead of just

MqttClient cl = new MqttClient("tcp://localhost:1883", "Publisher", new
MemoryPersistence());


such that when the connection to first address fails, a connection to the next address is tried.

Could someone please guide in this? Much appreciated.

Answer

Client libraries in many languages have this option. The list can be checked here: https://www.eclipse.org/paho/downloads.php

For those clients for which "high-availability" is marked, support list of urls to be specified using the "MqttConnectOptions".

Example:

        String[] URIs = {"address1","address2"};
        MqttConnectOptions mqttConnectOptions = new MqttConnectOptions();
        mqttConnectOptions.setServerURIs(URIs);