With the clear session flag set to FALSE, I am missing the published values

感情迁移 提交于 2019-12-01 12:10:42

问题


Is anyone has a logical explanation why despite I have the clear session flage = false I do not receive the updated published message I am subscribed to while i am not connected to the broker?

With the aorementioned flag set to false I ran my App, And i kept publishing to a topic some values (from the PC to the broker not from the Android device to the broker). And then I unpluged the usb of the Android Device frm the pc, and kept publishing some values again. When I plugged the usb to the pc again, i expected to see the values I recently published to that topic, but I did not receive any.

The topic I am publishing to is exactly the topic i am subscribed to, with QoS = 1.


回答1:


In order for messages to be queued for a client that is no longer connected to a broker, these things must be true:

  • Client must have originally connected with clean session set to false
  • Client must have subscribed with QoS>0
  • Messages to that topic must have been published with QoS>0
  • When the client reconnects it must have the same client id as when it disconnected
  • When the client reconnects it must have clean session set to false

My bet is that you are failing on either of the latter two points.




回答2:


You need to send the messages with the retain flag to be able to recieve the messages when you re-connect. The QoS defines how hard the broker/client will try to ensure that a message is received.

Have a read here http://mosquitto.org/man/mqtt-7.html on QOS, clean session and retained messages.



来源:https://stackoverflow.com/questions/26971783/with-the-clear-session-flag-set-to-false-i-am-missing-the-published-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!