使用mqtt QoS 2发布消息时,消息会丢失吗?
When publishing message with mqtt QoS 2, can it be lost?
我正在尝试使用 MQTT-Client Framework 实现 MQTT 客户端。我想确保我尝试发布的每条消息都能到达代理。我无法弄清楚 QOS2 的确切含义:它声明一条消息将只发送一次。是不是意味着当连接丢失时,它会在重新连接后自动尝试重传消息?或者这应该由应用程序处理?
同样在这个库中,默认情况下会自动重新连接?或者是否需要检查是否发生连接丢失然后尝试重新连接?
MQTT QoS 级别是对向接收方传递消息的保证,而不是对消息被发送方 sent/resent 的频率的保证。见 QoS section in the MQTT spec and an overview of MQTT QoS.
使用 MQTT QoS2 发布的消息意味着它将被传送恰好一次。可以多次发送消息以实现这种恰好一次的传递保证。
MQTT 的至少一次交付方面是使用 PUBLISH/PUBREC 握手实现的。如果发布者未收到确认其已发布消息的 PUBREC 数据包,则发布者将继续重新发送设置了 DUP 标志的 PUBLISH 消息。
QoS2 的 exactly once 交付方面是使用附加 PUBREL/PUBCOMP 握手实现的。接收方可以选择转发消息并丢弃 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.
因此,如果您的客户端遵循规范并且您使用的是持久会话 (CleanSession = 0),那么消息将被重新传输。
我正在尝试使用 MQTT-Client Framework 实现 MQTT 客户端。我想确保我尝试发布的每条消息都能到达代理。我无法弄清楚 QOS2 的确切含义:它声明一条消息将只发送一次。是不是意味着当连接丢失时,它会在重新连接后自动尝试重传消息?或者这应该由应用程序处理?
同样在这个库中,默认情况下会自动重新连接?或者是否需要检查是否发生连接丢失然后尝试重新连接?
MQTT QoS 级别是对向接收方传递消息的保证,而不是对消息被发送方 sent/resent 的频率的保证。见 QoS section in the MQTT spec and an overview of MQTT QoS.
使用 MQTT QoS2 发布的消息意味着它将被传送恰好一次。可以多次发送消息以实现这种恰好一次的传递保证。
MQTT 的至少一次交付方面是使用 PUBLISH/PUBREC 握手实现的。如果发布者未收到确认其已发布消息的 PUBREC 数据包,则发布者将继续重新发送设置了 DUP 标志的 PUBLISH 消息。
QoS2 的 exactly once 交付方面是使用附加 PUBREL/PUBCOMP 握手实现的。接收方可以选择转发消息并丢弃 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.
因此,如果您的客户端遵循规范并且您使用的是持久会话 (CleanSession = 0),那么消息将被重新传输。