stream_mqtt_preread module#

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

This module is not built by default; it should be enabled with the ‑‑with‑stream_mqtt_preread_module configure option. The packages in our repos have this module built-in.

Example Configuration#

Choosing an upstream server by the client ID:#

stream {

    mqtt_preread on;

    upstream mqtt {
        hash $mqtt_preread_clientid;
        # ...




mqtt_preread on | off;


mqtt_preread off;


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.


Unique client ID.


Optional username.