简体   繁体   English

MQTT上的连接丢失订阅了物联网服务器

[英]Connection lost on MQTT subscribe to Internet of Things Server

I'm writing a Java application to publish/subscribe to Internet of Things MQTT server using the Eclipse Paho Lib (org.eclipse.paho.client.mqtt3-1.0.2.jar), both on Device and Application side. 我正在编写一个Java应用程序,使用Eclipse Paho Lib(org.eclipse.paho.client.mqtt3-1.0.2.jar)在设备和应用程序端发布/订阅物联网MQTT服务器。

Connect works well with both credential types, and same seems to be the publish... What gives me the error is the subscribe: 连接适用于两种凭证类型,同样似乎是发布...什么给我的错误是订阅:

Trying it by mosquitto_sub command line, it loops like this: 通过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)
...

And so on. 等等。

When trying from java with an MqttAsyncClient, the subcribe() method returns, but then the waitForCompletion() method istantly trows: 当从带有MqttAsyncClient的java尝试时,subcribe()方法返回,但是waitForCompletion()方法显然是trows:

Connection lost (32109) - java.io.EOFException

This is the code I am running: 这是我正在运行的代码:

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

and then: 然后:

connect();

...

IMqttToken subToken = client.subscribe(topic, qos, null, null);
subToken.waitForCompletion();

Also, this error makes the lib to not relese the persistence path user by the AsyncClient, making it to trow a "Persistence Already in Use" exception on every retry, until I stop the JVM and manually clear that path, but i suppose this to be some sort of library bug. 此外,此错误使lib不会通过AsyncClient释放持久性路径用户,使其在每次重试时都会使用“持久性已使用”异常,直到我停止JVM并手动清除该路径,但我想这是是某种库bug。

Unfortunately, I can't (or don't know how) access the IoT-side mqtt server to realize what's going on in there. 不幸的是,我不能(或不知道如何)访问IoT端mqtt服务器以实现其中发生的事情。

Any ideas? 有任何想法吗? Thank you 谢谢

It appears your problem is likely due to invalid topic "matteo". 看来您的问题可能是由于无效主题“matteo”造成的。

For connecting to the IoT Foundation in Bluemix, you will need to follow the topic format as outlined in the IBM Internet of Things Foundation documentation here: https://docs.internetofthings.ibmcloud.com/messaging/applications.html 要在Bluemix中连接到IoT Foundation,您需要遵循IBM Internet of Things Foundation文档中概述的主题格式: https//docs.internetofthings.ibmcloud.com/messaging/applications.html

If both mosquitto_sub and your Paho Java client are having problems at the same point (SUBSCRIBE), that implies the problem with your broker. 如果mosquitto_sub和您的Paho Java客户端在同一点(SUBSCRIBE)都遇到问题,则表明您的代理存在问题。

I tried running this: 我试过这个:

mosquitto_sub -t matteo -i 'a:u5o0ux:tws' -d -h test.mosquitto.org

And got the output: 得到了输出:

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 received SUBACK
Subscribed (mid: 1): 0

Maybe you could try connecting your client to test.mosquitto.org , iot.eclipse.org or one of the other public MQTT brokers out there. 也许您可以尝试将您的客户端连接到test.mosquitto.orgiot.eclipse.org或其他公共MQTT代理之一。 Or you could run your own copy of a broker locally for testing. 或者您可以在本地运行您自己的代理副本以进行测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MQTT 和 SpringBoot 集成连接丢失 - MQTT and SpringBoot Integration Connection Lost 与应用程序服务器失去互联网连接时维护服务的机制 - Mechanism to maintain service when internet connection is lost with application server ActiveMQ + MQTT +订阅“ ActiveMQ.Advisory.Connection” - ActiveMQ + MQTT + subscribe to “ActiveMQ.Advisory.Connection” 在运行时检查互联网连接是否丢失 - Checking if the internet connection is lost at runtime 使用Spring Integration MQTT通过相同的连接发布和订阅 - Publish & Subscribe with Same Connection using Spring Integration MQTT 连接后,MQTT订阅客户端未收到消息 - MQTT subscribe client doesn't receive messages after connection 客户端断电或Netty断开Internet连接时如何检测客户端在服务器上的断开连接 - How to detect client's disconnect at server when client power off or lost internet connection in netty Android中如何处理没有互联网和丢失的连接? - How to handle with no Internet and lost connection in Android? 失去互联网连接后,MySQL连接会如何处理? - What happens to MySQL connection when internet connection is lost? MQTT-订阅方法不起作用 - MQTT - subscribe method is not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM