Closed samuelyhsu closed 1 year ago
If you use mqtt_cpp client and mqtt_cpp broker, then async published publish packet (QoS0) order is preserved.
For example,
clientP1 --- mqtt_cpp broker --- clientS1
Then clientS1 always receives payload A,B,C order.
If the underlying socket is different, order is not guaranteed.
For example,
clientP1 --- mqtt_cpp broker --- clientS1
clientP2 ---
Then clientS1 receives ABC, ACB, or BAC, order. A is always before C, but B can interrupt anyware.
If you use non mqtt_cpp broker, then the order depends on the broker implementation.
At least, the broker receives expected order (ABC for the first example), in other words, mqtt_cpp client(endpoint) never reorder publish QoS0 packet internally.
There is only one clientP1 and clientS1, publishing and receiving are all single-threaded, but broker is not mqtt_cpp, sent three messages ABC continuously , but the receiver received ACB, may be the broker rearranged the order? I use emqx as broker https://www.emqx.io/
I guess so.
You can try async_mqtt (mqtt_cpp's successor project) docker container broker.
https://github.com/redboltz/async_mqtt/blob/doc/README.md#run-on-the-docker-container
For testing you can replace emqx with async_mqtt broker, and observe the result.
I'll try it, thanks a lot!
publish a qos0 message with async_publish of async_client, other client subscribed to the message may receive the message in garbled order?