Field-by-field reference for the MQTT transport: session, sender and receiver options, credential URIs, mutual TLS, and dialing through a proxy.
See MQTT for sessions and a worked example, and MQTT behaviour for settlement, resilience and backpressure.
options.session.*)| Key | Type | Default | Description |
|---|---|---|---|
broker_url |
string | – | Single broker URL (e.g. tcp://host:1883). Folded into broker_urls when the list form is absent. |
broker_urls |
[]string | – | Broker URLs for failover. Ephemeral sessions may use multiple independent URLs. Persistent/exclusive sessions reject more than one distinct canonical URL because one managed-filter history cannot safely span independent broker-session domains. Canonical means the endpoint actually dialled: scheme aliases collapse (tcp/mqtt, and ssl/tls/mqtts/mqtt+ssl/tcps), an omitted port becomes the family default (1883 / 8883 / 80 / 443), host case, userinfo and fragment are ignored, and path/query count only for ws/wss. Two durable sessions spelled differently but reaching one endpoint are rejected as duplicate identities at startup instead of disconnecting each other on their shared client_id. A scheme outside that list is rejected. |
client_id |
string | – | MQTT client identifier. Required on the effective (merged) session config at build time, together with at least one broker URL (Config.ValidateEffectiveSession in config_plugin.go, enforced by Factory.NewSession); an empty value is accepted at parse time. For scale-out uniqueness from one shared config file, see client_id_suffix. |
client_id_suffix |
string | – | Opt-in per-instance uniquifier appended to client_id, required for clustered non-Exclusive $share consumers. hostname appends the process-cached hostname; for Persistent sessions it is safe only where hostnames are stable across restarts (StatefulSet/VM — NOT Deployments/ECS, where every rollout orphans the previous broker session and its queued QoS 1/2; the factory rejects this combination unless assert_stable_client_identity: true — see Deployment identity). nonce appends a process-cached random token and is allowed only for Ephemeral sessions. Unset leaves client_id verbatim. Exclusive rejects every suffix because failover resumes one stable shared client ID. |
assert_stable_client_identity |
bool | false |
Affirms that this deployment’s hostnames survive a restart, admitting the one combination the factory otherwise rejects at build time: a Persistent session with client_id_suffix: hostname. On a Kubernetes Deployment or an ECS service every rollout mints a new hostname, so a new client_id, so a new broker session — the previous session’s queued QoS 1/2 messages are stranded until session_expiry_interval expires them, which is loss by timeout and invisible to the bridge. Setting this is the operator vouching for a StatefulSet/VM identity profile; it does not make a Deployment or ECS safe. A warning is logged on every admitted session. Ignored for non-persistent modes and for any suffix other than hostname — see Deployment identity. |
keep_alive |
int | 30 |
Keep-alive interval in seconds. Explicit 0 disables the MQTT pinger — half-open-connection detection then rests on TCP keep-alive alone (much slower, and OS-dependent), so a dead-but-open socket can go unnoticed for minutes. The registry/blueprint path defaults to 30; a direct library consumer that sets 0 should understand this trade-off. |
connect_timeout |
duration | 30s |
Bounds the initial Start connection await |
reconnect_timeout |
duration | 30s |
Bounds each individual (re)connect attempt (TCP dial + TLS + CONNECT/CONNACK). Maps to autopaho ConnectTimeout; 0 → autopaho default (10s). |
reconcile_timeout |
duration | 30s (DefaultReconcileTimeout) |
Bounds each broker SUBSCRIBE / UNSUBSCRIBE issued while reconciling the session plan. The reconcile runs on a possibly deadline-less runtime context, so without this an unresponsive broker (SUBACK/UNSUBACK never arrives on a half-open connection) would hang the reconcile — and any startup / hot-reload step awaiting it — indefinitely. This is a liveness safety bound: a non-positive value is coerced up to 30s and cannot be disabled. |
reconnect_delay |
duration | 10s (DefaultReconnectDelay) |
Base delay of a jittered exponential reconnect backoff. Starts at reconnect_delay, grows 2× (reconnectBackoffFactor) per failed attempt, caps at reconnect_max_delay, then equal-jitters to [d/2, d) to desynchronise a reconnecting fleet (anti thundering-herd). 0 → 10s. |
reconnect_max_delay |
duration | 2m (DefaultReconnectMaxDelay) |
Caps the jittered-exponential reconnect envelope. Must be ≥ reconnect_delay; a smaller value is clamped up to the base at Start. 0 → 2m. |
clean_start |
bool | false |
MQTT 5 clean-start flag; consulted only for Persistent/Exclusive sessions. clean_start: true on a Persistent session wipes the broker-side session (subscriptions AND queued offline QoS 1/2) on every process restart — the backlog the mode exists to retain is discarded each time. Honoured as configured, with a construction-time warning; on Exclusive it is overridden to false (takeover loop). On MQTT 3.1.1 (protocol_version: v3.1.1) clean_start: true on a Persistent session is rejected: MQTT 3.1.1 has no flag that starts clean and still keeps the session. |
session_expiry_interval |
int | 0 |
MQTT 5 session expiry in seconds. For Persistent/Exclusive sessions a 0 is replaced at session creation (NewSession) with 86400 (24h) — a literal 0 would give zero offline retention. Ephemeral always uses 0. On MQTT 3.1.1 any value other than 0 is rejected: MQTT 3.1.1 cannot send a session expiry, so the broker decides how long a session lives (broker defaults: Mosquitto never expires it, EMQX after 2 h, AWS IoT after 1 h). Persistent/Exclusive sessions still use 86400 internally for redelivery admission; it is never sent and logs no warning. |
receive_maximum |
int | 0 → 192 (DefaultReceiveMaximum) |
MQTT 5 Receive Maximum: the most QoS 1/2 messages the broker may send before the session acknowledges them. It is a plain count: you set it, or it defaults to 192; nothing derives it. The same count sizes the session’s serialized dispatch queue and caps the messages waiting for a receiver to register (see Ingress limits are counts). 0 selects the default because 0 is illegal on the wire, and a warning is logged when it is unset. On MQTT 3.1.1 the value is not sent, because 3.1.1 has no Receive Maximum; the session enforces it locally instead. It must be at least the broker’s per-client in-flight limit (broker defaults: Mosquitto max_inflight_messages 20, EMQX max_inflight 32, AWS IoT 100). A broker that sends more unacknowledged QoS 1/2 publishes is refused on every connection as an ingress reject (MQTTIngressRejected): nothing is acked or lost, and the Error log asks you to raise this value. See broker limits. |
max_payload_bytes |
int | 0 → 262144 (DefaultMaxPayloadBytes) |
Maximum inbound application body, in bytes. It is a protocol message-size limit, not a memory estimate: CONNECT announces it to the broker as the Maximum Packet Size, which is this value plus a 128 KiB MQTT v5 metadata allowance, and the session enforces it. After TLS/WebSocket decoding but before Paho packet decoding, an adapter-owned connection guard frames one bounded wire packet, validates Remaining Length before allocation, rejects malformed PUBLISH structure and any packet above the announced total, and truncates a User Property list longer than 129 entries to 129 on the raw bytes so the SDK never decodes more (MQTTIngressUserPropertiesTruncated). The decoded callback then enforces the local caps the broker cannot see — an oversized body, more than 128 User Properties, or topic-plus-properties metadata over 128 KiB — by acking and dropping the packet (MQTTIngressPoisonDropped), never by failing the session. Values too large to keep the metadata allowance below the MQTT 256 MiB − 1 packet ceiling are rejected, never clamped. This does not limit outbound publishes. On MQTT 3.1.1 nothing is announced, because 3.1.1 has no Maximum Packet Size, so the broker forwards a PUBLISH of any size. The session keeps only the first max_payload_bytes + 1 payload bytes, discards the rest without buffering it, and the callback acks and drops the publish (MQTTIngressPoisonDropped); see oversized publishes. |
unmatched_grace |
duration | 30s |
Grace window after each connect during which an incoming publish matching no registered receiver filter is buffered (un-acked) awaiting handler registration. It is also the post-recycle no-replay verification window for managed-filter removal; a pinned matching replay or a shorter reconciliation deadline fails migration closed and preserves history. After the window a still-unmatched publish is split by whether a wanted subscription still covers its topic. A topic the session still wants whose handler registered late is retained un-acked and redelivered once the handler registers (MQTTRouterCoveredRetained) — never acked-dropped, so a late-registering live route cannot lose a QoS 1/2 message; only a covered QoS 0 publish the bounded buffer cannot hold is dropped best-effort (MQTTRouterCoveredDropped). An orphan topic no configured route covers (a leftover broker-side subscription on a resumed clean_start=false session) is acked, dropped, and UNSUBSCRIBEd (deduped, one warn per topic) to converge (MQTTRouterUnmatchedDropped, benign cleanup). 0 → DefaultUnmatchedGrace (30s). |
no_local |
bool | false |
Opt-in MQTT 5 No-Local. When true, every ordinary subscription is issued with the No-Local flag so the broker does not deliver a message back to the same session that published it — breaking the same-broker MQTT→MQTT self-delivery loop where a session that both subscribes and publishes on overlapping filters would otherwise receive and re-forward its own publishes (unbounded self-amplification). Default false preserves the least-surprising MQTT contract (a session receives its own publishes), so existing single-session round-trip topologies are unaffected. A shared subscription ($share/…) never sets No-Local even when this is true: MQTT 5 §3.8.3.1 makes No-Local on a shared subscription a Protocol Error the broker rejects with a DISCONNECT. Cross-bridge delivery is unaffected — No-Local is per-connection and distinct bridges use distinct client_ids. See ADR 0010. Rejected on MQTT 3.1.1, which has no No-Local: loop prevention must not disappear without notice. |
protocol_version |
string | v5 |
MQTT protocol version the session speaks: v5 (MQTT 5.0, the default; an empty value selects it) or v3.1.1. Any other value is rejected. The value is a string: a bare YAML 5 decodes as a number and is refused. MQTT 3.1 is not supported, and there is no automatic fallback between versions. On v3.1.1 a translator below the connection guard rewrites every packet between MQTT 5 and MQTT 3.1.1, so the other options keep their meaning. The configuration is rejected when it sets no_local, a non-zero session_expiry_interval, a password without a username, or clean_start: true on a Persistent session — MQTT 3.1.1 cannot express them. Headers and message identity are not carried (see message_id), and other behaviour degrades; one startup warning lists it. Switching an existing Persistent or Exclusive session between versions keeps its broker state key and its managed subscription history; see switching an existing session. See MQTT 3.1.1 and ADR 0022. |
message_id |
string | random |
How an MQTT 3.1.1 session sets the id of a message it receives, since an MQTT 3.1.1 PUBLISH carries no producer id: random (the default; an omitted key means the same) mints a fresh id per delivery, marked x-bridge.generated-id, and content_hash hashes the broker session, the topic and the payload, so a redelivery keeps its id but two different messages with identical content are treated as one. content_hash requires protocol_version: v3.1.1, any other value is rejected, and you should read message ids before you enable it. |
username |
string | – | Authentication username. Sent in the MQTT CONNECT packet in cleartext — see allow_plaintext_credentials and use a TLS broker scheme (ssl://, mqtts://, …). |
password |
string | – | Authentication password (redacted on marshal). Sent in the MQTT CONNECT packet in cleartext — protect it with a TLS broker scheme. |
allow_plaintext_credentials |
bool | false |
Opt IN to sending username/password over a non-TLS broker URL (tcp://, mqtt://, ws://, or schemeless). Default false fails closed: if credentials are configured and any broker_urls entry is not a TLS scheme, session build is rejected (the credentials would travel in cleartext). tls.enable does not satisfy this — autopaho selects TLS from the URL scheme only. Set true only for trusted transports (private mesh, TLS-terminating sidecar, or a localhost test broker). |
will.topic |
string | – | Last Will and Testament topic (required when will is set; no wildcards) |
will.payload |
string | – | Will message payload |
will.qos |
int | 0 |
Will QoS (0, 1, or 2) |
will.retain |
bool | false |
Will retain flag |
tls.enable |
bool | false |
Builds the client TLS material (CA / client cert / verification mode) below. Does not by itself select a TLS transport — autopaho dials TLS only when the broker URL scheme is a TLS scheme (ssl://, mqtts://, tls://, mqtt+ssl://, tcps://, wss://). On a tcp:// URL the built config is ignored and the connection stays cleartext, so pair tls.enable: true with a TLS scheme. |
tls.ca_cert_file |
string | – | CA certificate file path |
tls.cert_file |
string | – | Client certificate file path |
tls.key_file |
string | – | Client private key file path |
tls.ca_cert_pem |
string | – | CA certificate PEM material (in-memory; wins over ca_cert_file). Typically supplied by credential rotation. |
tls.cert_pem |
string | – | Client certificate PEM material (requires key_pem; wins over cert_file) |
tls.key_pem |
string | – | Client private key PEM material (redacted on marshal; requires cert_pem) |
tls.insecure_skip_verify |
bool | false |
Skip server certificate verification |
Every duration above accepts 0, which selects the documented default. A
negative value is rejected at configuration validation, so it can never
reach a session. Nothing downstream treats a negative duration as an error –
it becomes an already-expired context – so a build that accepted one would
start successfully and then fail every attempt it made, for a reason that is
invisible in the configuration.
The MQTT client applies its own deadline to each packet acknowledgement it waits for (CONNACK, SUBACK, UNSUBACK, PUBACK/PUBCOMP), inside the deadline the bridge already set. Its built-in default is 10 seconds – shorter than every budget on this page – so leaving it alone would silently override them: a SUBACK the bridge was willing to wait 30 seconds for would be abandoned at 10, failing a reconcile while the broker was answering normally.
There is no key for it. The session derives the budget as the longest of
connect_timeout, reconnect_timeout, reconcile_timeout, the timeout of
every sender bound to the session, and the 30-second sender default – so the
adapter-owned bound is always the one that governs. It is not a liveness bound
of its own: each packet operation already runs under its own deadline, and that
is what bounds an unresponsive broker.
One consequence is worth knowing when tuning shutdown: a SUBSCRIBE or
UNSUBSCRIBE still in flight when the session is closed now waits out
reconcile_timeout rather than being cut short at the client’s old 10-second
default. Cancelling the context passed to Reconcile still ends it
immediately, which is what the runtime does on shutdown, so this is visible
only to a library consumer that closes a session while holding a longer-lived
context open.
The ingress caps do not all apply at the same point. Three boundaries matter, and only the first two happen before the SDK builds Go objects:
| Boundary | What it enforces | What a violation costs |
|---|---|---|
| Broker (CONNECT-announced Maximum Packet Size) | max_payload_bytes + the 128 KiB metadata allowance, as ONE whole-packet limit. It is the only inbound limit a compliant broker enforces. |
Nothing reaches the bridge. |
| Predecode connection guard (raw bytes, after TLS/WebSocket, before Paho decodes) | Structural validity of the PUBLISH, Remaining Length validated before allocation, total size against the announced maximum, and the User Property list truncated to 129 entries on the raw bytes (MQTTIngressUserPropertiesTruncated). |
One raw wire packet buffered. A malformed packet or a total above the announced maximum drops the connection, not the session: the guard tries to send DISCONNECT (0x81 Malformed Packet or 0x95 Packet too large), closes the socket, and the session reconnects with a backoff that grows with consecutive rejects (MQTTIngressRejected). Only a broken broker can produce either. |
| Decoded publish callback (after Paho has built Go objects) | The LOCAL caps the broker cannot see: an oversized body, more than 128 User Properties, or topic-plus-properties metadata over 128 KiB. The packet is acked and dropped (MQTTIngressPoisonDropped), never failed. |
One fully decoded packet. The packet is refused only AFTER it has been decoded. |
The third row is the one to know: a packet that violates a local cap is decoded in full before anything refuses it. The property caps are split for this reason — 128 is what a packet may KEEP, 129 is the most the SDK will ever DECODE — so the guard bounds the decode while the callback still sees the violation and refuses the packet.
The CONNECT announces only a whole-packet Maximum Packet Size, so a compliant
broker may forward a packet whose metadata is nothing but five-byte (empty key,
empty value) User Properties — about 78,600 of them in a zero-payload packet at
the default limit. The SDK spends roughly 1.3 KiB decoding each one. The
predecode guard removes the excess on the raw bytes instead: the SDK never sees
more than 129 User Properties, the callback still refuses the packet, and every
such packet is counted on MQTTIngressUserPropertiesTruncated.
GoBridge does not estimate memory. It limits MQTT ingress by counts, plus the protocol message-size limit:
receive_maximum (default 192) caps how many QoS 1/2 messages the broker may
send before the session acknowledges them. The same count sizes the
session’s serialized dispatch queue and caps the messages waiting for a
receiver to register. A QoS 0 publish over a full queue or buffer is dropped
(MQTTRouterDropped); see
backpressure and dispatch.max_payload_bytes (default 256 KiB) is the message-size limit announced in
CONNECT as the Maximum Packet Size, together with the 128 KiB metadata
allowance.bridge.max_mqtt_sessions (optional, default 0 = no limit) caps the
number of MQTT sessions one configuration uses; see the
configuration reference.Each session’s limits depend only on its own configuration, so adding or
removing one MQTT session changes no other session. paho.Session.DispatchStats()
reports the dispatch queue’s depth and capacity, both counts. Choose the
process or task memory by measuring the deployment under its real load; see
deployment scaling.
options.sender.*)| Key | Type | Default | Description |
|---|---|---|---|
default_topic |
string | – | Fallback publish topic used when OutboundMessage.Address is empty. The publish topic is never read from Envelope.Subject. Validated as an MQTT publish topic at build time (wildcards +/#, the $share/ prefix, and null bytes are rejected), because it bypasses the runtime address validator — a malformed value would otherwise only fail at first publish, as a broker DISCONNECT that tears down the shared session for every route on it. |
qos |
int | 1 |
MQTT QoS level (0, 1, or 2) |
retain |
bool | false |
MQTT retain flag |
timeout |
duration | 30s |
Per-publish timeout, applied as the stricter of this value and the caller’s remaining deadline. The session raises the MQTT client’s per-packet acknowledgement budget to cover the longest timeout of any sender bound to it, so the value you configure is the one that governs a PUBACK wait (see Packet acknowledgement budget). On a bridge route the dispatcher already wraps every send in the route’s policy.send_timeout (default 30s), so a timeout shorter than the remaining route deadline tightens the publish while a longer one is capped by the route deadline — it never extends the route ceiling. Note the coercion asymmetry: unlike an explicit qos: 0 or keep_alive: 0 (honoured as-is), a configured timeout: 0 is coerced up to the 30s default at build. The 60s Send-time safety-net for a zero timeout is therefore reachable only by a direct library consumer that constructs SenderOptions and leaves Timeout at 0, bypassing the factory — via config, a 0 becomes 30s. See Resilience Behavior for the interaction with policy.send_timeout. |
throttle_retry_after |
duration | 500ms |
Retry-after hint attached to a publish failure only when the broker returns PUBACK/PUBREC reason 0x97 (Quota exceeded) – the one reason code that signals throttling. Other non-zero reason codes classify as generic errors with no back-off hint. Never applies on MQTT 3.1.1, where PUBACK and PUBREC carry no reason code. |
options.credentials_uri)credentials_uri is a top-level key under options:, a sibling of session:
and sender: (not a session key). It names a credential-store URI (file://…,
pms://…) that the runtime credential resolver reads at build time. The resolver
merges the resolved username, password, and TLS material
(tls_cert/tls_key/tls_ca) into the session options and removes the
credentials_uri key before the MQTT transport sees the config, so the secrets
never appear in the YAML. See
HTTP ingress with credentials
for the resolver walkthrough.
Token-style auth is supported: a password (or bearer token) with no username
sets the CONNECT password flag independently of the username flag, so a
token-in-password credential is no longer dropped for want of a username.
MQTT 3.1.1 forbids a password without a username, so on protocol_version:
v3.1.1 that combination is rejected: in the configuration, after
credentials_uri resolves, and on a live credential rotation, before the
session changes anything.
The two halves of mutual TLS are configured independently, and either can come from a store instead of the filesystem:
ca_cert_file / ca_cert_pem, or ca from the store).cert_file + key_file, cert_pem + key_pem, or cert/key
from the store).Pointing at a credential URI supplies both, so no certificate material appears in the YAML or on disk:
options:
credentials_uri: "pms:///gobridge/prod/mqtt" # AWS Parameter Store
session:
broker_url: "ssl://broker.example.com:8883" # TLS comes from the SCHEME
tls:
enable: true
insecure_skip_verify: false
The stored JSON supplies the material the resolver merges into tls:
{
"username": "bridge",
"password": "…",
"ca": "-----BEGIN CERTIFICATE-----\n…",
"cert": "-----BEGIN CERTIFICATE-----\n…",
"key": "-----BEGIN PRIVATE KEY-----\n…"
}
ca accepts a single PEM or a list, for a chain or during CA rotation. The
parser also accepts certPem/certificate and keyPem/privateKey as
aliases. Rotating any of it in the store is picked up by the credential refresh
path — see Credential rotation.
Two behaviours worth knowing, both fail-closed:
tls.enable. A tcp:// broker URL
stays cleartext even with enable: true. Use ssl://, mqtts://, tls://
or wss://.allow_plaintext_credentials: true is set explicitly. This is re-checked
after the store resolves, so a credentials_uri-only config cannot smuggle
secrets onto a tcp:// broker.The same pattern works for AMQP 0-9-1, AMQP 1.0 and Azure Service Bus.
ALL_PROXY (or all_proxy) routes broker dials through a SOCKS5 proxy, and
NO_PROXY (or no_proxy) exempts hosts from it. This holds for every broker
scheme, ws:// and wss:// included; HTTP_PROXY and HTTPS_PROXY are not
read. Both spellings are read on every dial, uppercase first, as in
golang.org/x/net/proxy and net/http, so no two resolvers can disagree.
Two behaviours are deliberate and differ from proxy.FromEnvironment:
http://, which is not a SOCKS proxy) returns an
error instead of quietly dialing direct. A proxy is a network-control
boundary; silently bypassing it is worse than a loud connect failure.ALL_PROXY=direct (or direct://) is an explicit opt-out, for a
container where the variable is set for other tools but the broker must be
reached without it.TLS broker connections derive the certificate ServerName from the broker URL
host on both the direct and the proxied path, so an ssl:// or wss://
connection through a proxy verifies the broker’s identity exactly as a direct
one does. Previously the proxied ssl:// path set no name at all, leaving a
certificate-validating proxied connection unable to verify the broker.
MQTT receivers still have no receiver-level options. Subscriptions are declared
in the topics[] array on the ReceiverDef, not in the receiver’s options
map, and each topics[] entry accepts an options.subscription block,
documented in Subscription Options Reference:
receivers:
- id: sensors-in
session_id: plant-broker
topics:
- topic: sensors/#
qos: 1
options:
subscription:
qos_recheck_interval: 30m
Every entry is validated at build time – the topic filter against the MQTT
v5 filter rules (wildcard placement, $share/<group>/<filter> shape, UTF-8, no
null bytes, length) and qos against 0/1/2. Both checks are repeated when the
session plan is reconciled, so a plan handed straight to a Session by a
library consumer fails the same way. Validating at build matters twice over: a
subscription only reaches the broker when the session manager reconciles the
plan, so a malformed filter would otherwise fail after the process had
started serving – and an out-of-range qos would not fail at all. The MQTT
client writes the level as qos & 0x03, so qos: 4 would reach the broker as
0: the route would believe it subscribed at-least-once while the broker
delivered at-most-once and never asked for an acknowledgement.
Use the factory for production composition (library-consumer note).
Factory.NewReceiveratomically reserves the session’s sole ingress receiver and returnsshared.ErrInvalidConfigfor a second call, including calls through another factory value or registry alias. The low-levelpaho.NewReceiverconstructor exists for adapter diagnostics and focused router tests; it bypasses factory preflight and must not be used to multiplex production routes onto one session. Receiver IDs remain globally unique in bridge configuration.
Keys of the options.subscription block on a receiver topics[] entry.
| Key | Type | Default | Description |
|---|---|---|---|
qos_recheck_interval |
duration | 1h |
How often a subscription the broker granted below the requested QoS (accepted as best effort) is re-subscribed to learn whether the broker grants the requested QoS again. 0s disables it (a bare 0 is rejected); a reconnect still re-evaluates. Minimum 1m. See QoS downgrade. |