How to ensure receiving messages from multiple topics in order?
Lets say I subscribe to two topics A and B and QoS 2 is given:
client.subscribeWith()
.topicFilter(“A”)
.qos(MqttQos.EXACTLY_ONCE)
.send();
client.subscribeWith()
.topicFilter(“B”)
.qos(MqttQos.EXACTLY_ONCE)
.send();
client.publishes().subscribe(SUBSCRIBED, this::onReceive);
When a publisher publishes in this order:
- message MA to topic A
- message MB to topic B
Will a subscriber as shown above always receive A before B?
Or is the only way setting Receive Maximum on broker and subscriber to 1?
See in MQTT 5 Reference:
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. Refer to section 4.9 Flow Control for details of how the Receive Maximum is used.