|
|
@@ -32,15 +32,19 @@ System Layers
|
|
|
-------------
|
|
|
|
|
|
1. Connection Layer:
|
|
|
+
|
|
|
Handle TCP and WebSocket connections, encode/decode MQTT packets.
|
|
|
|
|
|
2. Session Layer:
|
|
|
+
|
|
|
Process MQTT PUBLISH/SUBSCRIBE Packets received from client, and deliver MQTT messages to client.
|
|
|
|
|
|
3. PubSub Layer:
|
|
|
+
|
|
|
Dispatch MQTT messages to subscribers in a node.
|
|
|
|
|
|
4. Routing(Distributed) Layer:
|
|
|
+
|
|
|
Route MQTT messages between clustered nodes.
|
|
|
|
|
|
.. code::
|
|
|
@@ -65,8 +69,8 @@ This layer is built on the `eSockd`_ library which is a general Non-blocking TCP
|
|
|
|
|
|
This layer is also responsible for encoding/decoding MQTT frames:
|
|
|
|
|
|
-1. Parse MQTT frames received from client
|
|
|
-2. Serialize MQTT frames sent to client
|
|
|
+1. Parse MQTT frame received from client
|
|
|
+2. Serialize MQTT frame sent to client
|
|
|
3. MQTT Connection Keepalive
|
|
|
|
|
|
Main modules of this layer:
|
|
|
@@ -109,38 +113,37 @@ MQueue and Inflight Window
|
|
|
|
|
|
Concept of Message Queue and Inflight Window::
|
|
|
|
|
|
- |<----------------- Max Len ----------------->|
|
|
|
- -----------------------------------------------
|
|
|
-IN -> | Messages Queue | Inflight Window | -> Out
|
|
|
- -----------------------------------------------
|
|
|
- |<--- Win Size --->|
|
|
|
+ |<----------------- Max Len ----------------->|
|
|
|
+ -----------------------------------------------
|
|
|
+ IN -> | Messages Queue | Inflight Window | -> Out
|
|
|
+ -----------------------------------------------
|
|
|
+ |<--- Win Size --->|
|
|
|
|
|
|
1. Inflight Window to store the messages delivered and awaiting for PUBACK.
|
|
|
|
|
|
2. Enqueue messages when the inflight window is full.
|
|
|
|
|
|
-3. If the queue is full, dropped qos0 messages if store_qos0 is true,
|
|
|
- otherwise dropped the oldest one.
|
|
|
+3. If the queue is full, dropped qos0 messages if store_qos0 is true, otherwise dropped the oldest one.
|
|
|
|
|
|
The larger the inflight window size, the higher the throughput. The smaller the window size, the more strict the message order.
|
|
|
|
|
|
PacketId and MessageId
|
|
|
----------------------
|
|
|
|
|
|
-The 16bits PacketId is defined by MQTT Protocol Specification, used by client/server to PUBLISH/PUBACK packets. A GUID(128bits global unique Id) will be generated by the broker and assigned to a MQTT message.
|
|
|
+The 16bits PacketId is defined by MQTT Protocol Specification, used by client/server to PUBLISH/PUBACK packets. A GUID(128bits globally unique Id) will be generated by the broker and assigned to a MQTT message.
|
|
|
|
|
|
-Format of the global unique message id::
|
|
|
+Format of the globally unique message id:
|
|
|
|
|
|
- +------------------------+----------------+------------+
|
|
|
- | Timestamp | NodeID + PID | Sequence |
|
|
|
- +------------------------+----------------+------------+
|
|
|
- |<------- 64bits ------->|<--- 48bits --->|<- 16bits ->|
|
|
|
- +------------------------+----------------+------------+
|
|
|
++------------------------+----------------+------------+
|
|
|
+| Timestamp | NodeID + PID | Sequence |
|
|
|
++------------------------+----------------+------------+
|
|
|
+| <-------64bits-------> | <---48bits---> | <-16bits-> |
|
|
|
++------------------------+----------------+------------+
|
|
|
|
|
|
- 1. Timestamp: erlang:system_time if Erlang >= R18, otherwise os:timestamp
|
|
|
- 2. NodeId: encode node() to 2 bytes integer
|
|
|
- 3. Pid: encode pid to 4 bytes integer
|
|
|
- 4. Sequence: 2 bytes sequence in one process
|
|
|
+1. Timestamp: erlang:system_time if Erlang >= R18, otherwise os:timestamp
|
|
|
+2. NodeId: encode node() to 2 bytes integer
|
|
|
+3. Pid: encode pid to 4 bytes integer
|
|
|
+4. Sequence: 2 bytes sequence in one process
|
|
|
|
|
|
The PacketId and MessageId in a End-to-End Message PubSub Sequence::
|
|
|
|