1

How to find out where Paho Java client got actually connected to when it was called with list of severURIs.

I work on a client application where multiple equal brokers are used to achieve “High Availability” system. Paho is provided with list of all brokers to connect to:

MqttConnectOptions options = new MqttConnectOptions();
options.setServerURIs( new String[]{"tcp://broker1.com:1883", 
         "tcp://broker2.com:1883", "tcp://broker3.com:1883"} );

MqttClient mqttClient = new MqttClient("tcp://broker1.com:1883", 
         clientId, new MemoryPersistence());
mqttClient.connect(options);

After connect I would like to report where it has got actually connected to, but I do not know how. MqttClient.getServerURI() returns URI provided in MqttClient constructor regardless it is connected to.

According to documentation:

When an attempt to connect is initiated the client will start with the first serverURI in the list and work through the list until a connection is established with a server. If a connection cannot be made to any of the servers then the connect attempt fails.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.