4
Session Design
Feng Lee edited this page 2015-06-08 14:19:15 +08:00
This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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:

  1. The Clients subscriptions.
  2. 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.
  3. 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.
  4. all qos1, qos2 messages published to when client is disconnected. QoS 1 and QoS 2 messages pending transmission to the Client.
  5. 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)