Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [mosquitto-dev] Retained message not delivered when reconnecting with persistent session

Hi Alex,

> I am running the mosquitto-0.13-win32-bin\mosquitto-cygwin.exe broker:

I would suggest upgrading to something not *quite* so old... Not that
this relates to your problem.

> Then I post a retained message to a topic:
>
> mosquitto_pub.exe -r -m Off -t test/licht
>
> Finally when I subscribe to the topic the message is delivered just fine
> every time:
>
> mosquitto_sub -c -t test/licht
> Off
>
> mosquitto_sub -c -t test/licht
> Off
>
> However when I subscribe to another topic, the retained message isn't
> delivered anymore:
>
> mosquitto_sub -c -t xxx
>
> Should the retained message be delivered in the above call too?

No, this isn't the case. Retained messages are only delivered when a
client make a SUBSCRIBE request. As you aren't subscribing to
test/licht in your last example the retained message shouldn't be
delivered.

> I have used persistent session (the "-c") flag throughout all the calls and
> so the previous subscription to the "test/licht" topic should be restored
> automatically and thus the retained message "Off" delivered again.

You need to ensure that the client id is identical for each time you
use "-c", otherwise you are connecting with a different client and
will not restore the existing session. Later versions of mosquitto_sub
do not allow you to use -c without also specifying the client id. In
the example you give, it is not possible for you to know what the
client id was and hence not possible to recover the sessions.

> But this does not seem to happen and also I could not find any definition
> for using pertained messages with persistent sessions in the MQTT 3.1.1
> OASIS doc...

Retained messages and persistent sessions are pretty separate topics
really. Retained messages are really just about the SUBSCRIBE event
like I said.

It's also worth noting that MQTT 3.1.1 didn't exist when mosquitto
0.13 was released. In fact, the "new" MQTT 3.1 spec wasn't even a year
old at that point.

Cheers,

Roger


Back to the top