MQTT qos参数无效 [英] MQTT qos parameter has no effect

查看:391
本文介绍了MQTT qos参数无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在覆盆子服务器上安装了mosquitto服务器.

I have installed a mosquitto server on a raspberry server.

此服务器正常工作:我已经测试了mosquitto_sub和mosquitto_pub命令.

This server works fine: I have test with mosquitto_sub and mosquitto_pub commands.

我已经编写了这个python脚本:

I have write this python script:

import paho.mqtt.client as mqtt
import time

client = mqtt.Client('module_test_4')
client.connect('127.0.0.1', 1883, 10)

client.loop_start()


for i in range(10):
   client.publish('topic_2', "valeur %d" % i, qos=0)
   time.sleep(1)

client.loop_stop()
client.disconnect()

我已经在2个控制台上启动了此脚本两次:

I have launched this script twice on 2 consoles:

 mosquitto_sub -h 127.0.0.1 -i module_test_2 -t topic_2

工作正常:我在每个控制台上看到消息.

It works fine: I see messages on each console.

现在,我尝试将qos参数更改为0,1和2.

Now, i have tried to change qos parameter to 0,1 and 2.

我尝试运行python脚本,而不会出现mosquitto_sub的任何情况.

I have tried to run my python script without lauching any occurence of mosquitto_sub.

我当时想mosquitto将缓冲消息并在启动mosquitto_sub时再次发送它,但这是行不通的.

I was thinking mosquitto will buffer messages and send it again when mosquitto_sub will be launched but this does not work.

所以我想知道qos的工作原理...

So i am wondering how qos works...

谢谢

推荐答案

QOS一次仅适用于连接的一条分支.

QOS only applies to one leg of the connection at a time.

这意味着发布者/经纪人和经纪人/订户的QOS可能不同.

This means the QOS can be different between the publisher/broker and broker/subscriber.

因此,在您发布的示例中,您将发布者和代理之间的QOS设置为2,但仍是订阅者和代理之间的默认0.这意味着,就经纪人而言,订阅客户只需要QOS 0.

So in the example you have posted you set QOS to 2 between the publisher and the broker, but it is still the default 0 between the subscriber and the broker. This means that as far as the broker is concerned the subscribing client only wants QOS 0.

如果要使用mosquitto_sub进行测试,则还需要在命令行中包含更高的QOS.像这样断开连接之前,您需要在QOS 2上建立订阅:

If you want to test with mosquitto_sub you need to include a higher QOS on the command line as well. You need to have established a subscription at QOS 2 before disconnecting like so:

mosquitto_sub -h 127.0.0.1 -i module_test_2 -t topic_2 -q 2

您还需要告诉mosquitto_sub在重新连接时不要要求进行干净的会话:

You also need to tell mosquitto_sub not to ask for a clean session when it reconnects:

 mosquitto_sub -h 127.0.0.1 -i module_test_2 -t topic_2 -q 2 -c 

这篇关于MQTT qos参数无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆