mqtt - 使用 mqtt QoS 2 发布消息时,会丢失吗?

标签 mqtt ios-mqtt-client-framework

我正在尝试使用 MQTT-Client Framework 实现 MQTT 客户端.我想确保我尝试发布的每条消息都会到达代理。我无法弄清楚 QOS2 的确切含义:它指出一条消息将只发送一次。是不是意味着当连接丢失时,它会在重新连接后自动尝试重传消息?或者这应该由应用程序处理?

同样在这个库中,重新连接是默认自动完成的吗?或者需要检查connectionLost是否发生,然后尝试重新连接?

最佳答案

MQTT QoS 级别是对将消息传送到接收者的保证,而不是发送者发送/重新发送消息的频率。见 QoS section in the MQTT spec和一个 overview of MQTT QoS .

使用 MQTT QoS2 发布的消息意味着它将被传递 恰好一次 .可以多次发送消息以实现这种恰好一次传递的保证。

MQTT 的至少一次交付方面是使用 PUBLISH/PUBREC 握手实现的。如果发布者没有收到确认其发布消息的 PUBREC 数据包,则发布者将继续重新发送设置了 DUP 标志的 PUBLISH 消息。

使用附加的 PUBREL/PUBCOMP 握手实现 QoS2 的恰好一次交付方面。接收者可以在two different points选择转发消息并丢弃重复消息。 .

Does it mean that when connection is lost, it will try to retransmit the message automatically after reconnecting? Or this should be handled by the app?



MQTT 规范涵盖 message delivery retries :

When a Client reconnects with CleanSession set to 0, both the Client and Server MUST re-send any unacknowledged PUBLISH Packets (where QoS > 0) and PUBREL Packets using their original Packet Identifiers. This is the only circumstance where a Client or Server is REQUIRED to redeliver messages.



因此,如果您的客户端遵循规范并且您使用的是持久 session (CleanSession = 0),那么消息将被重新传输。

关于mqtt - 使用 mqtt QoS 2 发布消息时,会丢失吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53529189/

相关文章:

java - 如何安装 Eclipse Paho 客户端 View

ruby - 发布确认 - MQTT

mqtt - 编译 Mosquitto 1.4 时出错

c - 我必须连接到 MQTT 代理吗?

windows - 如何在Windows中的Docker上测试mqtt?

ios - MQTT-Client-Framework 在后台保持运行

iOS - MQTT 客户端框架确实连接/工作