0

I have written code (mosquitto_publish()) using Mosquitto to publish data to AWS.

My problem is the sequence with which data is arriving on the MQTT broker. In the Paho client, I see waitForCompletion(), but nothing similar in Mosquitto. Would anyone please help me in dealing with this problem ?

4

1 回答 1

0

根据mosquitto_publich 文档,该函数在发送“成功”时返回。MQTT 不保证消息到达的顺序,因此可以说您应该注意到达而不是发送,并避免两条消息相互竞争到代理。使用 QoS 0,客户端永远不知道消息是否到达;需要 QoS 1 或 2,为此交换额外的通信。提高服务质量,你可以使用mosquitto_max_inflight_messages_set(mosq, 1) 以便客户端将任何其他消息排队,直到它收到来自服务器的确认。这可能比“等待”完成更有效,因为非 MQTT 操作可以继续。如果您发送大量消息,队列可能会堆积。

更复杂的替代方法是无限制地发送消息,但每个消息都包含一个索引,以便订阅者可以在收到时对它们进行排序(为此它需要自己的队列和延迟)。如果此负担将落在多个订户身上,则不推荐。

于 2019-03-15T23:19:58.793 回答