When using quality of service (QoS) 0, the publish function does not receive a response from the server ("fire and forget"). For the more reliable QoS levels 1 and 2, the server responds, but the publish call does not wait for the response; it returns control to the application as soon as the publish request is successfully sent. After publish returns, and before the complete publish response has been received from the server, a message is said to be "in-flight."
When the connect option maxInflight
is set to 1, only one publication message can be in-flight at a time. If a message is still in-flight when another publish call is made, the second call has two possible behaviors:
- If a messageArrived callback has been set, then it suspends until the first publication message response has been completely received.
- If no messageArrived callback has been set, you use the receive function. In this case, the publish function returns an error code indicating that the in-flight queue is full, and the publish is to be retried later.
If the maxInflight is set to 10, up to 10 outgoing publication messages can be in-flight at the same time. The waitForCompletion
call can be used to ensure that the publication response has been received for a particular message.
The only valid values for the maxInflight
are 1 and 10. The value of 10 can provide higher throughput for QoS 1 and 2 messages, but it means that message order might not be maintained in the case of a failure. The recommended value of 1 provides greater ensurance of maintaining message order.
Parent topic: Using the MQTT C Client: XPD622