Table of Contents
Overview
The broker redesigned a simple in-memory message queue/session mechanism in 0.9.0, to support offline queue and inflight window.
Notice that MQTT is not an enterprise messaging queue. MQTT assume that client should be online in most of the time.
If the broker restarted or crashed, all the messages queued will be gone.
Design
|<------------ Max Length of Queue ---------->|
-----------------------------------------------
IN -> | Pending Messages | Inflight Window | -> Out
-----------------------------------------------
|<--Max Inflight-->|
-
Inflight Window to store the messages awaiting for ack.
-
Suspend IN messages when the persistent client disconnected, or inflight window is full.
-
If the queue is full, dropped qos0 messages if store_qos0 is true, otherwise dropped the oldest pending one.
-
Tune the inflight window to balance message order and throughput. Large value for high throughput, and smaller for message order assurance.
etc/emqttd.config
%% Session
{session, [
%% Expired after 2 days
{expired_after, 48},
%% Max number of QoS 1 and 2 messages that can be “in flight” at one time.
%% 0 means no limit
{max_inflight, 100},
%% Max retries for unack Qos1/2 messages
{unack_retries, 3},
%% Retry after 4, 8, 16 seconds
{unack_timeout, 4},
%% Awaiting PUBREL Timeout
{await_rel_timeout, 8},
%% Max Packets that Awaiting PUBREL, 0 means no limit
{max_awaiting_rel, 0}
]},
%% Session
{queue, [
%% Max queue length. enqueued messages when persistent client disconnected,
%% or inflight window is full.
{max_length, 1000},
%% Low-water mark of queued messsages
{low_watermark, 0.2},
%% High-water mark of queued messsages
{high_watermark, 0.6},
%% Queue Qos0 messages?
{queue_qos0, true}
]}
Code
src/emqttd_session.erl
src/emqttd_mqueue.erl
Version: 1.0(Draft) Author: Feng Lee feng@emqx.io