社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  MQ

带有mqtt的rabbitmq在连接时发送消息

programmingFox • 6 年前 • 704 次点击  

我正在使用mqtt启动程序( https://github.com/jpmens/mqtt-launcher )当接收到负载为“0”的特定MQTT消息时执行命令。

这是配置文件

logfile         = '/home/user/mqtt-launcher/logfile'
mqtt_broker     = 'broker'       # default: 'localhost'. If using TLS, this must be set to the domain name signed by$
mqtt_port       = 1883              # default: 1883
mqtt_clientid   = 'mqtt-launcher-1'
mqtt_username   = ''
mqtt_password   = ''
mqtt_tls        = None              # default: No TLS

topiclist = {

    # topic            payload value  program & arguments
    "channel/dostuff" : {
       '0' : [
          '/usr/bin/ssh', 
          '-i', 
          '/home/user/.ssh/privatekey', 
          'user@host',
          'script.sh'
          ]
    }
}

每次启动python脚本时,shell脚本执行两次。

但是,如果发送了负载为“0”的MQTT消息,我希望它只执行一次。

我确保在清除订阅时隐式创建的队列之前是空的,然后启动mqtt启动程序,但在程序连接后脚本仍然执行两次。

当我奔跑 user@localhost:~$ mosquitto_sub -h broker -p 1883 -t 'channel/dostuff' -v -u 'user' -P 'mysecurepassword' 我得到 channel/dostuff 0

我不熟悉蚊子,但我认为这意味着我收到了一条信息,对吗?

我打开了retain选项,重新启动了openhab和rabbitmq,但仍然发送消息。以下是openhab mqtt.cfg:

broker.url=tcp://broker:1883
broker.user=openhab
broker.pwd=mysecurepassword
broker.qos=1
broker.retain=false
broker.async=false
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/30893
 
704 次点击  
文章 [ 1 ]  |  最新文章 6 年前
hardillb
Reply   •   1 楼
hardillb    6 年前

您已经发布了一条包含有效负载的消息 0 以及保留位集。

这意味着当客户机订阅该主题时,带有保留位集的最后一条消息将被传递给该客户机。

您可以通过将保留位集和空有效负载的消息发布到同一主题来清除保留的消息。您可以使用mosquitto_pub命令执行此操作,如下所示:

mosquitto_pub -t "channel/dostuff" -u 'user' -P 'password' -r -n

您应该确保在发布消息时,通常不会设置保留位。