简体   繁体   English

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

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

I'm currently working on a MQTT client using python, and come to the point where i can create clients that publish and subscribe to the Mosquitto broker.我目前正在使用 python 开发 MQTT 客户端,并且可以创建发布和订阅 Mosquitto 代理的客户端。

The problem is that, no matter what, the mosquitto broker will send only a maximum of 20 PUBLISH packets to a subscriber client, even if it stay connected for long periods of time.问题是,无论如何,mosquitto 代理最多只会向订阅者客户端发送 20 个 PUBLISH 数据包,即使它长时间保持连接也是如此。

How can I configure mosquitto to send more than 20 PUBLISH packets to the subscriber client?如何配置 mosquitto 向订阅者客户端发送超过 20 个 PUBLISH 数据包?

Mosquitto log:蚊子日志:

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))

at this point, the mosquitto broker won't send more packets to the subscriber, excepting PINGRESP when the subscriber client sends PINGREQ in order to remain connected to the broker.此时,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)

I'll be happy to provide the code for the client if it's actually needed.如果确实需要,我很乐意为客户提供代码。

Later edit: Maybe it's worth mentioning稍后编辑:也许值得一提
If there are more subscribers on one topic, this behavior is not observable, the broker sends packets without stopping at any point whatsoever.如果一个主题有更多订阅者,则这种行为是不可观察的,代理会发送数据包而不会在任何时候停止。

20 messages sounds like you are hitting the max number of inflight messages (max number of unacknowledged messages) 20 条消息听起来您正在达到最大的机上消息数(最大未确认消息数)

The messages are QOS 1 so your client needs to acknowledge them.这些消息是 QOS 1,因此您的客户需要确认它们。

Solved this problem by modifying max_inflight_messages to 0 in the mosquitto.conf file.通过修改mosquitto.conf文件中的max_inflight_messages0解决了这个问题。

I had a different solution to an exact same situation:对于完全相同的情况,我有不同的解决方案:

In my publisher, I had not written "client.loop_start()" and "client.loop_stop()" around the publish message.在我的发布者中,我没有围绕发布消息编写“client.loop_start()”和“client.loop_stop()”。 Adding these two lines resolved the problem.添加这两行解决了这个问题。

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

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