Protocol Specification
If CleanSession is set to 0, the Server MUST resume communications with the Client based on state from the current Session (as identified by the Client identifier). If there is no Session associated with the Client identifier the Server MUST create a new Session. The Client and Server MUST store the Session after the Client and Server are disconnected[MQTT-3.1.2-4].
CleanSession set to 0, the Server MUST store further QoS 1 and QoS 2 messages that match any After the disconnection of a Session that had subscriptions that the client had at the time of disconnection as part of the Session state
It MAY also store QoS 0 messages that meet the same criteria.
Session State in the broker consists of:
- The Client’s subscriptions.
- inflight qos1, qos2 messages sent to the client but unacked, QoS 1 and QoS 2 messages which have been sent to the Client, but have not been completely acknowledged.
- inflight qos2 messages received from client and waiting for pubrel. QoS 2 messages which have been received from the Client, but have not been completely acknowledged.
- all qos1, qos2 messages published to when client is disconnected. QoS 1 and QoS 2 messages pending transmission to the Client.
- Optionally, QoS 0 messages pending transmission to the Client.
Session State in the client consists of:
QoS 1 and QoS 2 messages which have been sent to the Server, but have not been completely acknowledged.
QoS 2 messages which have been received from the Server, but have not been completely acknowledged.
session manager
%% lookup sesssion
emqtt_sm:lookup_session(ClientId)
%% Start new or resume existing session
emqtt_sm:start_session(ClientId)
%% destroy session, discard all data
emqtt_sm:destory_session(ClientId)
%% close session, save all data
emqtt_sm:close_session(ClientId)
session supervisor
usage?
session
%%system process
process_flag(trap_exit, true),
session:start()
session:subscribe(
session:publish(
session:resume(
session:suspend(
%%destory all data
session:destory(
%%save all data
session:close()
sm and session
sm manage and monitor session
client and session
client(normal process)<--link to -->session(system process)
Version: 1.0(Draft) Author: Feng Lee feng@emqx.io