The Will Message MUST be published after the Network Connection is subsequently closed and either the Will Delay Interval has elapsed or the Session ends, unless the Will Message has been deleted by the Server on receipt of a DISCONNECT packet with Reason Code 0x00 (Normal disconnection) or a new Network Connection for the ClientID is opened before the Will Delay Interval has elapsed [MQTT-3.1.2-8].
Situations in which the Will Message is published include, but are not limited to:
An I/O error or network failure detected by the Server.
The Client fails to communicate within the Keep Alive time.
The Client closes the Network Connection without first sending a DISCONNECT packet with a
Reason Code 0x00 (Normal disconnection).
The Server closes the Network Connection without first receiving a DISCONNECT packet with a
Reason Code 0x00 (Normal disconnection).
The Will Message MUST be removed from the stored Session State in the Server once it has been published or the Server has received a DISCONNECT packet with a Reason Code of 0x00 (Normal disconnection) from the Client [MQTT-3.1.2-10].
The Server SHOULD publish Will Messages promptly after the Network Connection is closed and the Will Delay Interval has passed, or when the Session ends, whichever occurs first. In the case of a Server shutdown or failure, the Server MAY defer publication of Will Messages until a subsequent restart. If this happens, there might be a delay between the time the Server experienced failure and when the Will Message is published.
Moquette changes
[x] fire will after the delay interval passed
[x] save and reload will message and delay interval in SessionData
[x] on new client connection with same ID remove the existing will schedule if present
[x] fire will when connection is closed and the first that manifest between willDelay and Session's close (session expiry)
[x] on disconnect with normal disconnection remove the will schedule, if present
[x] on server restart recreate the will schedule
[x] handle disconnect with return code with 0x04 disconnect with will message, so that a Will is fired also if the Session was closed properly.
[x] store all MQTT 5 Will's optional properties (payload format indicator, message expiry interval, content type, response topic, correlation data and user property*)
MQTT specs
The Will Message MUST be published after the Network Connection is subsequently closed and either the
Will Delay Interval
has elapsed or the Session ends, unless the Will Message has been deleted by the Server on receipt of a DISCONNECT packet with Reason Code 0x00 (Normal disconnection) or a new Network Connection for the ClientID is opened before the Will Delay Interval has elapsed[MQTT-3.1.2-8]
. Situations in which the Will Message is published include, but are not limited to:The Will Message MUST be removed from the stored Session State in the Server once it has been published or the Server has received a DISCONNECT packet with a Reason Code of 0x00 (Normal disconnection) from the Client
[MQTT-3.1.2-10]
.The Server SHOULD publish Will Messages promptly after the Network Connection is closed and the Will Delay Interval has passed, or when the Session ends, whichever occurs first. In the case of a Server shutdown or failure, the Server MAY defer publication of Will Messages until a subsequent restart. If this happens, there might be a delay between the time the Server experienced failure and when the Will Message is published.
Moquette changes
disconnect with will message
, so that a Will is fired also if the Session was closed properly.payload format indicator
,message expiry interval
,content type
,response topic
,correlation data
anduser property
*)