4

If there is only a single broker, a single publisher, a single topic and clean session, in this simplified case,

can msg delivery order on subscriber side be guaranteed to be the same as send order on publisher side? Will it be affected by QoS?

Ye XIA
  • 45
  • 8

1 Answers1

4

Section 4.6 from the MQTT 3.1.1 spec covers message ordering:

4.6 Message ordering

A Client MUST follow these rules when implementing the protocol flows defined elsewhere in this chapter:

  • When it re-sends any PUBLISH packets, it MUST re-send them in the order in which the original PUBLISH packets were sent (this applies to QoS 1 and QoS 2 messages) [MQTT-4.6.0-1]
  • It MUST send PUBACK packets in the order in which the corresponding PUBLISH packets were received (QoS 1 messages) [MQTT-4.6.0-2]
  • It MUST send PUBREC packets in the order in which the corresponding PUBLISH packets were received (QoS 2 messages) [MQTT-4.6.0-3] It MUST send PUBREL packets in the order in which the corresponding PUBREC packets were received (QoS 2 messages) [MQTT-4.6.0-4]

A Server MUST by default treat each Topic as an "Ordered Topic". It MAY provide an administrative or other mechanism to allow one or more Topics to be treated as an "Unordered Topic" [MQTT-4.6.0-5].

When a Server processes a message that has been published to an Ordered Topic, it MUST follow the rules listed above when delivering messages to each of its subscribers. In addition it MUST send PUBLISH packets to consumers (for the same Topic and QoS) in the order that they were received from any given Client [MQTT-4.6.0-6].

Having read that I would conclude that messages will normally (unless the broker specifically set to use unordered topics) be sent in order, but if a high QOS message is not acknowledged properly it may be resent which could result in it being redelivered out of sequence.

hardillb
  • 54,545
  • 11
  • 67
  • 105
  • thanks a lot for your answer, Just a small comment, I would prefer QOS 1 than "a high QOS message". – Ye XIA Jun 29 '16 at 09:13
  • High QOS is basically anything other than 0 – hardillb Jun 29 '16 at 09:14
  • Yes, but QOS 2 msg will not be redelivered. – Ye XIA Jun 29 '16 at 09:16
  • The broker will attempt to redeliver a QOS 2 message if it has not been acknowledged, so it is possible it would be delivered correctly later than a properly acknowledged message that had been published later – hardillb Jun 29 '16 at 09:19