← Back to the chapter · Previous detail · Next detail →

Technical detail · MQTT Python: Reliable Client Patterns

MQTT topic matching and reason-code interpretation

MQTT clients select messages using topic filters and receive protocol outcomes as reason codes.

A topic is a routing name with slash-separated levels. The broker routes messages; client IDs identify clients. Access-control lists (ACLs) set permissions; backoff increases retry waits.

In topic filters, + matches exactly one level and a final # matches zero or more levels. Without wildcards, matching is exact. A filter beginning with + or # does not match topics beginning with $. To receive the system branch, subscribe explicitly to $SYS/#, or to the individual \$SYS/... topics you need, subject to permission. A topic match predicts routing, not actual receipt.

A reason code must be interpreted for its protocol version. Success permits normal messaging; protocol errors call for a compatible client and valid packets; identity and permission errors call for client-ID, credential and ACL checks. Server unavailability, overload and rate limits call for bounded backoff; quota failures call for inspecting the actual resource limit. Unsupported wildcards require explicit topic names. Unknown values are not evidence of a successful connection.

The next detail collects selected protocol responses for lookup. Values depend on the protocol version and packet type; this is not an exhaustive MQTT 5 reason-code list.

← Back to the chapter · Previous detail · Next detail →