MQTT Preread#

Enables extracting client IDs and usernames from CONNECT packets for Message Queuing Telemetry Transport (MQTT) versions 3.1.1 and 5.0.

When building from the source code, this module isn’t built by default; it should be enabled with the ‑‑with‑stream_mqtt_preread_module build option.

In packages and images from our repos, the module is included in the build.

Configuration Example#

Choosing an upstream server by the client ID:#

stream {

    mqtt_preread on;

    upstream mqtt {
        hash $mqtt_preread_clientid;
        # ...
    }
}

Directives#

mqtt_preread#

Syntax

mqtt_preread on | off;

Default

mqtt_preread off;

Context

stream, server

Controls extracting information from CONNECT packets during the preread phase. If the setting is on, its surrounding context will have the following variables populated.

Built-in Variables#

See the details of the value semantics in the specification of MQTT versions 3.1.1 and 5.0.

$mqtt_preread_clientid#

Unique client ID.

$mqtt_preread_username#

Optional username.