我正在编写一个 Java 应用程序来使用 Eclipse Paho Lib (org.eclipse.paho.client.mqtt3-1.0.2.jar) 在设备和应用程序端发布/订阅物联网 MQTT 服务器。
Connect 适用于两种凭证类型,并且似乎是发布...给我的错误是订阅:
通过 mosquitto_sub 命令行尝试,它循环如下:
Client a:u5o0ux:tws sending CONNECT
Client a:u5o0ux:tws received CONNACK
Client a:u5o0ux:tws sending SUBSCRIBE (Mid: 1, Topic: matteo, QoS: 0)
Client a:u5o0ux:tws sending CONNECT
Client a:u5o0ux:tws received CONNACK
Client a:u5o0ux:tws sending SUBSCRIBE (Mid: 2, Topic: matteo, QoS: 0)
Client a:u5o0ux:tws sending CONNECT
Client a:u5o0ux:tws received CONNACK
Client a:u5o0ux:tws sending SUBSCRIBE (Mid: 3, Topic: matteo, QoS: 0)
Client a:u5o0ux:tws sending CONNECT
Client a:u5o0ux:tws received CONNACK
Client a:u5o0ux:tws sending SUBSCRIBE (Mid: 4, Topic: matteo, QoS: 0)
...
等等。
当使用 MqttAsyncClient 从 java 中尝试时,subcribe() 方法返回,但随后 waitForCompletion() 方法立即出现:
Connection lost (32109) - java.io.EOFException
这是我正在运行的代码:
String tmpDir = System.getProperty("java.io.tmpdir");
MqttDefaultFilePersistence dataStore = new MqttDefaultFilePersistence(tmpDir);
...
// Construct a non blocking MQTT client instance
client = new MqttAsyncClient(getMQTTBrokerURL(), clientId, dataStore);
// Set this wrapper as the callback handler
client.setCallback(this);
接着:
connect();
...
IMqttToken subToken = client.subscribe(topic, qos, null, null);
subToken.waitForCompletion();
此外,此错误使库无法通过 AsyncClient 释放持久性路径用户,使其在每次重试时抛出“持久性已在使用”异常,直到我停止 JVM 并手动清除该路径,但我想这是是某种库错误。
不幸的是,我无法(或不知道如何)访问 IoT 端 mqtt 服务器以了解其中发生了什么。
有任何想法吗?谢谢