mosquitto mqtt 代理不会向订阅者发送超过 20 个发布数据包

mosquitto mqtt broker won't send more than 20 publish packets to subscriber

我目前正在使用 python 开发 MQTT 客户端,现在我可以创建发布和订阅 Mosquitto 代理的客户端。

问题是,无论如何,mosquitto 代理最多只会向订阅者客户端发送 20 个 PUBLISH 数据包,即使它保持连接很长时间也是如此。

如何配置 mosquitto 向订阅者客户端发送超过 20 个 PUBLISH 数据包?

蚊子日志:

1608918436: Received PUBLISH from publisher (d1, q1, r0, m1, '/OS', ... (3 bytes))
1608918436: Sending PUBLISH to subscriber (d0, q1, r0, m17, '/OS', ... (3 bytes))
1608918436: Sending PUBACK to publisher (m1, rc0)
1608918438: Received PUBLISH from publisher (d1, q1, r0, m1, '/OS', ... (3 bytes))
1608918438: Sending PUBLISH to subscriber (d0, q1, r0, m18, '/OS', ... (3 bytes))
1608918438: Sending PUBACK to publisher (m1, rc0)
1608918440: Received PUBLISH from publisher (d1, q1, r0, m1, '/OS', ... (3 bytes))
1608918440: Sending PUBLISH to subscriber (d0, q1, r0, m19, '/OS', ... (3 bytes))
1608918440: Sending PUBACK to publisher (m1, rc0)
1608918442: Received PUBLISH from publisher (d1, q1, r0, m1, '/OS', ... (3 bytes))
1608918442: Sending PUBLISH to subscriber (d0, q1, r0, m20, '/OS', ... (3 bytes))

此时,mosquitto 代理不会向订阅者发送更多数据包,但当订阅者客户端发送 PINGREQ 以保持与代理的连接时 PINGRESP 除外。

1608918442: Sending PUBACK to publisher (m1, rc0)
1608918442: Received PINGREQ from subscriber
1608918442: Sending PINGRESP to subscriber
1608918444: Received PUBLISH from publisher (d1, q1, r0, m1, '/OS', ... (3 bytes))
1608918444: Sending PUBACK to publisher (m1, rc0)
1608918446: Received PUBLISH from publisher (d1, q1, r0, m1, '/OS', ... (3 bytes))
1608918446: Sending PUBACK to publisher (m1, rc0)

如果确实需要,我很乐意为客户提供代码。

稍后编辑:也许值得一提
如果一个主题上有更多订阅者,这种行为是不可观察的,代理会在任何时候不停地发送数据包。

通过将max_inflight_messages修改为0解决了这个问题mosquitto.conf 文件.

20 条消息听起来您正在达到最大传输消息数(最大未确认消息数)

消息是 QOS 1,因此您的客户端需要确认它们。

我对完全相同的情况有不同的解决方案:

在我的发布者中,我没有在发布消息周围写上“client.loop_start()”和“client.loop_stop()”。添加这两行解决了问题。