can mqtt msg delivery order be guaranteed in simplified case?
Asked Answered
G

2

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?

Goon answered 29/6, 2016 at 8:42 Comment(0)
T
5

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.

Tailing answered 29/6, 2016 at 9:6 Comment(4)
thanks a lot for your answer, Just a small comment, I would prefer QOS 1 than "a high QOS message".Goon
High QOS is basically anything other than 0Tailing
Yes, but QOS 2 msg will not be redelivered.Goon
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 laterTailing
A
0

For MQTT v5.0 spec leaves "non normative comment" that:

If both Client and Server set Receive Maximum to 1, they make sure that no more than one message is “in-flight” at any one time. In this case no QoS 1 message will be received after any later one even on re-connection. For example a subscriber might receive them in the order 1,2,3,3,4 but not 1,2,3,2,3,4.

Similar comment is in spec of v3.x but without any tips how to keep in-flight messages at 1.

Acescent answered 13/4 at 12:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.