如何在 Mosquitto 中禁用 mqtt 重复消息

How to disable mqtt duplicate message in Mosquitto

我在 运行 Ubuntu 18.04 机器上安装了 mosquitto。下面是它的 mosquitto.conf & bridge.conf 文件。

`mosquitto.conf`

# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example

persistence true
persistence_location /var/lib/mosquitto/

log_dest file /var/log/mosquitto/mosquitto.log

include_dir /etc/mosquitto/conf.d

下面是桥接文件

connection iothub-bridge
log_type all
address ttpvluk.azure-devices.net:8883
remote_username ttpvluk.azure-devices.net/TX-S2-PVL-0E01
remote_password SharedAccessSignature sr=ttpvluk.azure-devices.net&sig=ylwqmY3N5%2FbnOdaNok4p90pTWg%3D&se=253402280999.36&skn=iothubowner
remote_clientid TX-S2-PVL-0E01
bridge_cafile /etc/ssl/certs/ca-certificates.crt
try_private false
cleansession false
start_type automatic
bridge_insecure false
bridge_protocol_version mqttv311
bridge_tls_version tlsv1.2
notifications false
keepalive_interval 36000
autosave_interval 30

topic # out 2 devices/TX-S2-PVL-0E01/messages/events/ devices/TX-S2-PVL-0E01/messages/events/
topic # in 2 devices/TX-S2-PVL-0E01/messages/devicebound/ devices/TX-S2-PVL-0E01/messages/devicebound/

现在,我从 python 代码向 mosquitto 代理发送了一些数据,我正在 azure 物联网设备资源管理器上检查它。但我只是不断收到带有 dup true check 的第一条消息。下面是截图

同样在 mosquitto 日志中,我可以看到它在我的 python 代码停止时一次又一次地发送数据。

1648738705: Bridge local.TX-S2-PVL-0E01 doing local SUBSCRIBE on topic devices/TX-S2-PVL-0E01/messages/events/#
1648738705: Connecting bridge (step 1) iothub-bridge (ttpvluk.azure-devices.net:8883)
1648738705: Connecting bridge (step 2) iothub-bridge (ttpvluk.azure-devices.net:8883)
1648738705: Bridge TX-S2-PVL-0E01 sending CONNECT
1648738706: Received CONNACK on connection local.TX-S2-PVL-0E01.
1648738706: Bridge local.TX-S2-PVL-0E01 sending UNSUBSCRIBE (Mid: 974, Topic: devices/TX-S2-PVL-0E01/messages/events/#)
1648738706: Bridge local.TX-S2-PVL-0E01 sending SUBSCRIBE (Mid: 975, Topic: devices/TX-S2-PVL-0E01/messages/devicebound/#, QoS: 2, Options: 0x00)
1648738706: Sending PUBLISH to local.TX-S2-PVL-0E01 (d1, q2, r0, m10, 'devices/TX-S2-PVL-0E01/messages/events/', ... (169 bytes))
1648738706: Sending PUBLISH to local.TX-S2-PVL-0E01 (d1, q2, r0, m11, 'devices/TX-S2-PVL-0E01/messages/events/', ... (169 bytes))
1648738706: Sending PUBLISH to local.TX-S2-PVL-0E01 (d1, q2, r0, m12, 'devices/TX-S2-PVL-0E01/messages/events/', ... (169 bytes))
1648738706: Sending PUBLISH to local.TX-S2-PVL-0E01 (d1, q2, r0, m13, 'devices/TX-S2-PVL-0E01/messages/events/', ... (169 bytes))
1648738706: Sending PUBLISH to local.TX-S2-PVL-0E01 (d1, q2, r0, m14, 'devices/TX-S2-PVL-0E01/messages/events/', ... (169 bytes))
1648738706: Sending PUBLISH to local.TX-S2-PVL-0E01 (d1, q2, r0, m15, 'devices/TX-S2-PVL-0E01/messages/events/', ... (169 bytes))
1648738706: Sending PUBLISH to local.TX-S2-PVL-0E01 (d1, q2, r0, m16, 'devices/TX-S2-PVL-0E01/messages/events/', ... (169 bytes))
1648738706: Sending PUBLISH to local.TX-S2-PVL-0E01 (d1, q2, r0, m19, 'devices/TX-S2-PVL-0E01/messages/events/', ... (169 bytes))
1648738706: Sending PUBLISH to local.TX-S2-PVL-0E01 (d1, q2, r0, m20, 'devices/TX-S2-PVL-0E01/messages/events/', ... (169 bytes))
1648738706: Sending PUBLISH to local.TX-S2-PVL-0E01 (d1, q2, r0, m21, 'devices/TX-S2-PVL-0E01/messages/events/', ... (169 bytes))
1648738706: Sending PUBLISH to local.TX-S2-PVL-0E01 (d1, q2, r0, m22, 'devices/TX-S2-PVL-0E01/messages/events/', ... (169 bytes))
1648738706: Sending PUBLISH to local.TX-S2-PVL-0E01 (d1, q2, r0, m23, 'devices/TX-S2-PVL-0E01/messages/events/', ... (169 bytes))
1648738706: Sending PUBLISH to local.TX-S2-PVL-0E01 (d1, q2, r0, m24, 'devices/TX-S2-PVL-0E01/messages/events/', ... (169 bytes))
1648738706: Sending PUBLISH to local.TX-S2-PVL-0E01 (d1, q2, r0, m27, 'devices/TX-S2-PVL-0E01/messages/events/', ... (169 bytes))
1648738706: Sending PUBLISH to local.TX-S2-PVL-0E01 (d1, q1, r0, m28, 'devices/TX-S2-PVL-0E01/messages/events/', ... (169 bytes))
1648738706: Sending PUBLISH to local.TX-S2-PVL-0E01 (d1, q1, r0, m29, 'devices/TX-S2-PVL-0E01/messages/events/', ... (169 bytes))
1648738706: Sending PUBLISH to local.TX-S2-PVL-0E01 (d1, q1, r0, m30, 'devices/TX-S2-PVL-0E01/messages/events/', ... (169 bytes))
1648738706: Sending PUBLISH to local.TX-S2-PVL-0E01 (d1, q1, r0, m31, 'devices/TX-S2-PVL-0E01/messages/events/', ... (169 bytes))
1648738706: Sending PUBLISH to local.TX-S2-PVL-0E01 (d1, q1, r0, m32, 'devices/TX-S2-PVL-0E01/messages/events/', ... (169 bytes))
1648738706: Sending PUBLISH to local.TX-S2-PVL-0E01 (d1, q1, r0, m35, 'devices/TX-S2-PVL-0E01/messages/events/', ... (169 bytes))
1648738706: Received UNSUBACK from local.TX-S2-PVL-0E01
1648738706: Received SUBACK from local.TX-S2-PVL-0E01

我该如何解决这个问题?

Azure IoT 中心不支持 QOS 2

https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-mqtt-support#sending-device-to-cloud-messages

您已将新娘配置为使用 QOS 2 发送消息