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?
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?
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.
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.
© 2022 - 2024 — McMap. All rights reserved.