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
.
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.
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