0
我使用net.sf.xenqtt的0.9.6版将消息发送到ActiveMQ服务器。在启动时创建一个新的MqttClient:xenqtt:检测mqttClient何时尝试重新连接
SyncMqttClient mqttClient = new SyncMqttClient(broker, syncListener, threadPoolSize, config);
并测试其连接:
ConnectReturnCode returnCode = mqttClient.connect(clientId, true, clientUserName, clientPassword);
if (returnCode != ConnectReturnCode.ACCEPTED) {
// all OK
如果其中它连接的服务器出现故障,mqttClient尝试重新连接i.a.w.其ReconnectionStrategy,并吐出日志信息,如:
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)
可以看我的日志条目,但mqttClient本身似乎并不有一种方法来告诉我,它有连接困难。
确定xenqtt是否处于“正在重新连接”状态 - 既不关闭也不完全打开的技术是什么?或者你会推荐我完全使用不同的mqtt客户端软件包?
非常感谢您确认轮询当前连接状态的方法不存在。 – 2014-10-13 16:51:39