简体   繁体   English

MQTT如何知道经纪人状态

[英]MQTT How to know the Broker Status

In a web application with MQTT in python (using paho-mqtt lib) I would like to know if there is a way to get the broker status in real time, because the only way that i find is to store the variable "rc" into the method on_connect but it's more like a client/connection state. 在Python中使用MQTT的Web应用程序中(使用paho-mqtt lib),我想知道是否存在一种实时获取代理状态的方法,因为我发现的唯一方法是将变量“ rc”存储到on_connect方法,但更像是客户端/连接状态。

EDIT 1 : after reading mosquitto broker documentation, i found that you can subscribe to '$SYS/broker/connection/#' which is supposed to give you back 1 if the connection is up and 0 if it goes down. 编辑1:阅读mosquitto经纪人文档后,我发现您可以订阅'$SYS/broker/connection/#' ,如果连接打开,则应该给您1,如果断开则返回0。 However when i do : 但是当我这样做时:

subscribe.callback(self.message_callback, '$SYS/broker/connection/#', port = port, hostname=broker, auth=authentication, protocol=client.MQTTv31, tls=TLS)

impossible to get payload and topic this message although i'm doing exactly the same command to get messages from my sensors except that the topic is '#' and it's working perfectly. 尽管我正在执行与从传感器获取消息完全相同的命令,但是主题为'#'且工作正常,但无法获取有效载荷和此消息的主题。

Does anyone knows why ? 有人知道为什么吗?

There is no way to poll the state of the connection to the broker from the client. 没有办法从客户端轮询到代理的连接状态。

The on_disconnect callback should be called when the connection to the broker is dropped. 当断开与代理的连接时,应调用on_disconnect回调。

This should be kicked off when the keep alive times out, but also as the result of a failure to publish (if you try to publish data before the timeout expires). 当保持活动超时时,这应该开始,这也是由于发布失败的结果(如果您尝试在超时到期之前发布数据)。

Also the rc from a call to the publish command will indicate if the connection has dropped. 调用发布命令的rc也将指示连接是否断开。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM