← Back to team overview

mosquitto-dev team mailing list archive

Re: [Question #147696]: Can mosquitto allow -r without saving last


Question #147696 on mosquitto changed:

    Status: Open => Answered

Roger Light proposed the following answer:
Retained messages are intended for situations where the value for the topic changes at unknown times and may change infrequently. A good example would be the state of a door - open or closed. You only change the value of the topic when the door opens or closes. Making the message retained here means that any client subscribing to the door topic will get an instant response as to the current state of the door without having to wait for it to change. An important point is that when the broker sends a retained message like
this it is marked as retained so that the client can tell it isn't fresh data generated at that instant.

Again, not exactly what you're asking but related and worth knowing - if
you want to clear a retained message on a topic, send a retained message
of zero length.

What I think you're asking for is provided by the "clean session" option. If set to false, this tells the broker that when your client
disconnects, all of its subscriptions should be saved and furthermore any messages (with QoS 1 or 2 only) that come in on those
subscriptions should be saved as well. When your client reconnects, it will receive those messages. This is limited by the
max_queued_messages variable - so if more than 100 messages (by default) are queued then new ones will be dropped.

You received this question notification because you are a member of
Mosquitto Dev, which is an answer contact for mosquitto.