MQTT 5.0 Message delivery retry and reason code

Viewed 106

In MQTT 5.0 specification, it states that 'If PUBACK or PUBREC is received containing a Reason Code of 0x80 or greater the corresponding PUBLISH packet is treated as acknowledged' But in reason code section, it states that 'Reason Codes less than 0x80 indicate successful completion of an operation. The normal Reason Code for success is 0. Reason Code values of 0x80 or greater indicate failure.'

MQTT 5.0 specification

Do they have any relationship?

Q1:Why Reason Code values of 0x80 or greater indicate failure while PUBACK ontaining a Reason Code of 0x80 or greater is treated as acknowledged?

Q2:Besides, does it mean PUBACK containing a Reason Code less than Reason Code of 0x80 is treated as unacknowledged?

1 Answers

Why Reason Code values of 0x80 or greater indicate failure while PUBACK containing a Reason Code of 0x80 or greater is treated as acknowledged?

The full text of MQTT-4.4.0-2 is:

If PUBACK or PUBREC is received containing a Reason Code of 0x80 or greater the corresponding PUBLISH packet is treated as acknowledged, and MUST NOT be retransmitted.

This relates to retransmission; QOS1+ messages will be retried (upon reconnection) if they are not acknowledged. MQTT-4.4.0-2 is stating that the receipt of a PUBACK/PUBREC with a reason code that indicates an error (0x80+) should should not be resent.

You might be able to conceive of a recoverable error (say 'broker overloaded') where it would make sense to retry the message; MQTT-4.4.0-2 ensures the specification is clear that the PUBLISH should not be resent.

Besides, does it mean PUBACK containing a Reason Code less than Reason Code of 0x80 is treated as unacknowledged?

No; the sentence only relates to reason codes > 0x80. Non-error responses are covered elsewhere - e.g.

[MQTT-4.3.2-3] In the QoS 1 delivery protocol, the sender MUST treat the PUBLISH packet as “unacknowledged” until it has received the corresponding PUBACK packet from the receiver.

[MQTT-4.3.3-3] In the QoS 2 delivery protocol, the sender MUST treat the PUBLISH packet as “unacknowledged” until it has received the corresponding PUBREC packet from the receiver.

It could be argued that these two statements mean that MQTT-4.4.0-2 is not required but including it ensures the spec is clear with regards to how errors should be handled.

Related