蚊子经纪人保留多条消息 [英] mosquitto broker retain multiple messages
问题描述
我要在EC2的Ubuntu上运行mosquitto代理.我也在/etc/mosquitto/mosquitto.conf
I am having mosquitto broker running on Ubuntu on EC2. Also I did a change max_queued_messages 1000
and max_inflight_messages 10
in /etc/mosquitto/mosquitto.conf
我正在使用 qos = 2 和保持启用状态向该代理发布.对于发布,我正在使用mosquitto_pub -t 1 -m "{c:{d:\"pN\",m:\"Pr1\"}}" -r -q 2
.和订户端,我正在使用具有相同qos = 2的org.eclipse.paho.android.service:1.0.2
库.
并且仅由options.setMqttVersion(MqttConnectOptions.MQTT_VERSION_3_1)
为client.connect(options)
的参数提供单个选项.
I am publishing to this broker with qos=2 and retain enabled. For publishing I am using mosquitto_pub -t 1 -m "{c:{d:\"pN\",m:\"Pr1\"}}" -r -q 2
. And subscriber side I am using org.eclipse.paho.android.service:1.0.2
library with same qos=2.
and only providing single option by options.setMqttVersion(MqttConnectOptions.MQTT_VERSION_3_1)
for parameters to client.connect(options)
.
如果连接到服务器的订户设备由于任何原因断开连接并再次重新连接,那么问题就来了,那么仅得到一条最后保留的消息,则丢失了所有消息之间的所有内容.
即使没有任何东西发布,在重新连接后仍然会得到最后的保留消息,该消息在断开连接之前可能已被订户设备获取.
Problem is coming if subscriber device connected to the server disconnects and reconnects again due to any reason, then getting only single last retained message, it is missing the all in between messages.
And also if nothing even published yet, still after reconnecting gets the last retained message which subscriber device might had already got before disconnecting.
我希望重新连接后,订户应该获得断开期间发布的所有消息,如果已经获得,则不应再次显示.想知道如何以及在哪里做.
I want that after reconnecting subscriber should get all messages which were published in the period of disconnection and if already got then should not shown again. Wanted to know how and where to do it.
推荐答案
订阅主题时,即使在没有任何QOS级别之前已经传递了主题,也会始终传递最后发布的保留消息.这是有意的,并且如果将消息发布为保留状态,则无法停止它. (请注意,发布带有保留标志的消息将替换上一条保留的消息,并且不会使所有保留的消息排队.)
The last retained message published will always be delivered when you subscribe to a topic even if it has already been delivered before no mater what QOS level. This is intentional and there is no way to stop it if the message is published as retained. (Just to be clear, publishing a message with the retained flag will replace the last retained message and does not queue up all retained messages.)
对于在断开/重新连接之间不获取消息发布,这意味着客户端通过了cleansession=true
连接选项.如果要发送丢失的消息,则需要确保在连接时将cleansession
标志设置为false
.这完全与是否发布带有保留标志的邮件无关.
As for not getting the messages published between a disconnect/reconnect this implies that the client it passing the cleansession=true
connection option. If you want to have the missed messages delivered then you need to ensure the cleansession
flag is set to false
at connection time. This is totally independent of if messages are published with the retained flag.
这篇关于蚊子经纪人保留多条消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!