Reputation: 14924
I want to focus on the MQTT standard and less the implementations.
I'm particularly interested in the risk of data loss where a client subscriber disconnects prematurely.
I realise that QOS 0 may be lost. I realise that with clean session set to 1 on connect a client is automatically unsubscribed on disconnect and therefore messages between disconnect and re-subscribe may be lost.
So, assuming a QOS 1 or 2 subscription, and assuming clean session is set to 0 on connect, will the broker just queue up messages until the client returns?
If the client never returns is the broker entitled to abandon the client session (implicitly unsubscribing it)?
Upvotes: 3
Views: 6590
Reputation: 931
http://www.steves-internet-guide.com/mqtt-clean-sessions-example/ Long story short, in order to receive all messages that are published while client is disconnected, you need to:
clean session
set to false
qos>=1
qos>=1
The maximum number of message store in broker is broker-dependent. For example in mosquitto
, the maximum number of messages can be specified in the config file with max_queued_messages count
. Set count to 0 to store unlimited messages (not recommended), the default value for mosquitto is 100 messages.
Upvotes: 4
Reputation: 59816
It's been a while since I dug that deeply into the v3.x spec (and it has changed for v5 where session expiry is explicit and configurable).
Sessions are supposed to last forever, but brokers such as mosquitto have options such as persistent_client_expiration
to say how long it should maintain the queue of messages. These options tend to be added to prevent memory/storage leaks for transient clients.
Upvotes: 3