Can mosquitto allow -r without saving last

Asked by Joe B

Can anyone tell me if I can send a mosquitto message (let's say using mosquitto_pub) and have that message be "retained" but...in a reasonable way?

Meaning...right now if I use -r I think it is, the message is retained Forever. I read your docs, makes sense for that purpose but not for many many other purposes.

For example:

I want to send a teacher a message:

1.) Hey Teacher

...They aren't connected.

2.) When they connect I want them to see the message (and any others stored).

THEN...

3.) If they log off, and log back on...I want them to see Nothing (unless I have posted a new message for them).

Does this seem like a normal thing? Please advise. Thanks.

Joe

Question information

Language:
English Edit question
Status:
Answered
For:
mosquitto Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Roger Light (roger.light) said :
#1

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.

Can you help with this problem?

Provide an answer of your own, or ask Joe B for more information if necessary.

To post a message you must log in.