0

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.

Amrmsmb
  • 1
  • 27
  • 104
  • 226

2 Answers2

9

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.

ralight
  • 11,033
  • 3
  • 49
  • 59
  • so clear, i reconnect wit different client id. here is my mistake – Amrmsmb Nov 17 '14 at 13:25
  • hi, kindly i would like to inquire about whther or not i am able to use passwrd and username in my pub and sub messages? i read the to use a pass and username you should have al least mosquitto V3.1 and mine is V 1.3.5. now i do not know whther my version is V 1.3.5 or V 3.5 because in a website they specified the version as a set of 2 numbers and mine is 3 numbers.moreover, the pass and user name are never working in my messages – Amrmsmb Nov 17 '14 at 16:58
  • 2
    The comments aren't really an appropriate place for a discussion. – ralight Nov 18 '14 at 11:21
0

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.

Matt.
  • 1,043
  • 1
  • 12
  • 20
  • it says in the QoS section. ..... This means that when the client disconnects, any subscriptions it has will remain and any subsequent QoS 1 or 2 messages will be stored until it connects again in the future. – Amrmsmb Nov 17 '14 at 12:09
  • @Matt - retained messages are a different issue. – ralight Nov 17 '14 at 12:58