1
votes

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.

2

2 Answers

2
votes

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);
0
votes

Just try to connect to the master, surround the call with appropriate error handling. If timed out or connection error, simply have code in handlers to call slave instead. If no response there either, bail out and assume the chain is broken.

Also the cluster could use a different configuration to expose only a single IP, which makes more sense. So that here are one alias queue facing out but logical queues on different machines in the cluster. This will help you later if you want to distribute to externals the possibility to connect to the cluster.