Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is message order preserved in MQTT messages?

Tags:

mqtt

I wonder if the message sent order is preserved. That is, when a publisher sends a sequence of messages, is each subscriber guaranteed to receive the same sequence as the publisher had sent it? For both clean and persistent sessions?

like image 745
Kar Avatar asked Jun 20 '15 14:06

Kar


People also ask

Does MQTT guarantee order?

A summary of the message ordering capabilities in MQTT 3.1. 1 can be found in the specification itself here. In summary: no guarantees are made about the relative ordering of messages published with different QoS values.

Are MQTT messages stored?

The job of an MQTT broker is to filter messages based on topic, and then distribute them to subscribers. There is no direct connection between a publisher and subscriber. All clients can publish (broadcast) and subscribe (receive). MQTT brokers do not normally store messages.

What is retain message in MQTT?

Normally if a publisher publishes a message to a topic, and no one is subscribed to that topic the message is simply discarded by the broker. However the publisher can tell the broker to keep the last message on that topic by setting the retained message flag.

How long do MQTT messages last?

Message Expiry Interval in MQTT 5 When the retained=true option is set on the PUBLISH message, this interval also defines how long a message is retained on a topic. Publish Packet with Message Expiry Interval set to 120 seconds. The retainFlag is set to "true", so the message will also be retained for 120 seconds.


Video Answer


1 Answers

A summary of the message ordering capabilities in MQTT 3.1.1 can be found in the specification itself here.

In summary:

  • no guarantees are made about the relative ordering of messages published with different QoS values. (for example, QoS 0 can over take QoS 2 for example as it involves a single packet rather than the 4 packets of the latter).
  • QoS 0 messages will be delivered in order (albeit messages may get lost)
  • QoS 2 messages will be delivered in order
  • QoS 1 allows for message duplicates - it is possible a duplicate will arrive after the first instance of the next message that was published.

QoS 1 ordering can be guaranteed if the client/broker only allow a single message inflight at any time.

like image 178
knolleary Avatar answered Sep 21 '22 21:09

knolleary