Steve Hansen Smythe
Steve Hansen Smythe

Reputation: 2847

xenqtt: detecting when mqttClient is trying to reconnect

I'm using version 0.9.6 of net.sf.xenqtt to send messages to an ActiveMQ server. At startup I create a new MqttClient:

SyncMqttClient mqttClient = new SyncMqttClient(broker, syncListener, threadPoolSize, config);

and test its connection:

ConnectReturnCode returnCode = mqttClient.connect(clientId, true, clientUserName, clientPassword);
if (returnCode != ConnectReturnCode.ACCEPTED) {
    // all OK

If the server to which it's connected goes down, the mqttClient tries to reconnect i.a.w. its ReconnectionStrategy, and spits out log messages such as:

ERROR xenqtt - Failed to connect MqttClientChannel[localAddress:N/A,remoteAddress:N/A]
java.net.ConnectException: Connection refused
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
    at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:716)
    at net.sf.xenqtt.message.AbstractMqttChannel.finishConnect(AbstractMqttChannel.java:193)
    at net.sf.xenqtt.message.ChannelManagerImpl.doConnect(ChannelManagerImpl.java:362)
    at net.sf.xenqtt.message.ChannelManagerImpl.doIO(ChannelManagerImpl.java:312)
    at net.sf.xenqtt.message.ChannelManagerImpl.access$000(ChannelManagerImpl.java:47)
    at net.sf.xenqtt.message.ChannelManagerImpl$1.run(ChannelManagerImpl.java:92)
    at java.lang.Thread.run(Thread.java:745)

I can see the log entries, but the mqttClient itself doesn't seem to have a method to tell me that it's having difficulty connecting.

What is the technique for determining if xenqtt is in the "is-reconnecting" state - neither closed nor entirely open? Or would you recommend that I use a different mqtt client package entirely?

Upvotes: 0

Views: 297

Answers (1)

impentaj
impentaj

Reputation: 16

The disconnect method of the MqttClientListener is called whenever the connection drops. The "reconnecting" param tells you whether the client will try to reconnect. There is no method you can call to poll for current connection status.

As for your questions about changing clients: I think xenqtt is the preferred MQTT library but I am one of the project authors so I may be biased. We try to respond to tickets promptly so feel free to open a ticket with any questions: http://sourceforge.net/p/xenqtt/tickets/

Upvotes: 0

Related Questions