PacketId and MessageId

This commit is contained in:
Feng 2016-04-02 14:48:50 +08:00
parent d75d3719e1
commit 313f4568dd
1 changed files with 23 additions and 20 deletions

View File

@ -32,15 +32,19 @@ System Layers
------------- -------------
1. Connection Layer: 1. Connection Layer:
Handle TCP and WebSocket connections, encode/decode MQTT packets. Handle TCP and WebSocket connections, encode/decode MQTT packets.
2. Session Layer: 2. Session Layer:
Process MQTT PUBLISH/SUBSCRIBE Packets received from client, and deliver MQTT messages to client. Process MQTT PUBLISH/SUBSCRIBE Packets received from client, and deliver MQTT messages to client.
3. PubSub Layer: 3. PubSub Layer:
Dispatch MQTT messages to subscribers in a node. Dispatch MQTT messages to subscribers in a node.
4. Routing(Distributed) Layer: 4. Routing(Distributed) Layer:
Route MQTT messages between clustered nodes. Route MQTT messages between clustered nodes.
.. code:: .. 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: This layer is also responsible for encoding/decoding MQTT frames:
1. Parse MQTT frames received from client 1. Parse MQTT frame received from client
2. Serialize MQTT frames sent to client 2. Serialize MQTT frame sent to client
3. MQTT Connection Keepalive 3. MQTT Connection Keepalive
Main modules of this layer: Main modules of this layer:
@ -109,38 +113,37 @@ MQueue and Inflight Window
Concept of Message Queue and Inflight Window:: Concept of Message Queue and Inflight Window::
|<----------------- Max Len ----------------->| |<----------------- Max Len ----------------->|
----------------------------------------------- -----------------------------------------------
IN -> | Messages Queue | Inflight Window | -> Out IN -> | Messages Queue | Inflight Window | -> Out
----------------------------------------------- -----------------------------------------------
|<--- Win Size --->| |<--- Win Size --->|
1. Inflight Window to store the messages delivered and awaiting for PUBACK. 1. Inflight Window to store the messages delivered and awaiting for PUBACK.
2. Enqueue messages when the inflight window is full. 2. Enqueue messages when the inflight window is full.
3. If the queue is full, dropped qos0 messages if store_qos0 is true, 3. If the queue is full, dropped qos0 messages if store_qos0 is true, otherwise dropped the oldest one.
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. The larger the inflight window size, the higher the throughput. The smaller the window size, the more strict the message order.
PacketId and MessageId 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 | | Timestamp | NodeID + PID | Sequence |
+------------------------+----------------+------------+ +------------------------+----------------+------------+
|<------- 64bits ------->|<--- 48bits --->|<- 16bits ->| | <-------64bits-------> | <---48bits---> | <-16bits-> |
+------------------------+----------------+------------+ +------------------------+----------------+------------+
1. Timestamp: erlang:system_time if Erlang >= R18, otherwise os:timestamp 1. Timestamp: erlang:system_time if Erlang >= R18, otherwise os:timestamp
2. NodeId: encode node() to 2 bytes integer 2. NodeId: encode node() to 2 bytes integer
3. Pid: encode pid to 4 bytes integer 3. Pid: encode pid to 4 bytes integer
4. Sequence: 2 bytes sequence in one process 4. Sequence: 2 bytes sequence in one process
The PacketId and MessageId in a End-to-End Message PubSub Sequence:: The PacketId and MessageId in a End-to-End Message PubSub Sequence::