Bridging mosquitto MQTT brokers

Bridging lets one Mosquitto broker connect to another and selectively share topics between them. The local broker opens an MQTT client session to the remote broker and republishes messages according to your rules.
A Mosquitto bridge is defined in mosquitto.conf
with a connection
block. You specify the remote address plus topic rules of the form:
topic <pattern> [in|out|both] [qos] [local-prefix] [remote-prefix]
in
= import from remote to local;out
= export local → remote;both
= two-way.- Optional prefixes remap topics to avoid loops and to keep trees distinct.
- Defaults: direction =
out
, QoS =0
.
Minimal, working examples
1) Simple two-way bridge (no remapping)
# /etc/mosquitto/config/mosquitto.conf
persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
listener 1883
connection bridge_name
address SERVER:1883
bridge_attempt_unsubscribe true
cleansession true
remote_username NAME
remote_password PASSWORD
remote_clientid mqtt_bridgeclient
try_private true
topic # both 0 "" ""
This forwards all topics in both directions. Start simple like this, then narrow patterns. (Be careful: “# both” without remapping can create loops if both sides mirror each other.)
2) Safe two-way bridge with remapping (recommended)
Use prefixes so each side knows where a message came from:
connection site-to-core
address core.example.net:1883
remote_username bridge-user
remote_password bridge-pass
try_private true
notifications true
# Remap whole trees to avoid loops
topic # both 1 local/ core/
Here, local publishes like sensors/room1/temp
appear on the remote as core/sensors/room1/temp
. Remote publishes under core/...
appear locally under local/...
.
Practical tips & gotchas
- Prevent loops: prefer unique
local-prefix
/remote-prefix
on both sides; leavetry_private true
to help loop detection. - Retained messages & sessions:
cleansession true
avoids surprise queued subscriptions after reconnects; adjust per your retention strategy.
References
- Official
mosquitto.conf(5)
bridge options & examples — syntax, topic remapping, TLS, reconnection, notifications. Eclipse Mosquitto - Steve’s Internet Guide – Bridge usage/config & SSL — approachable walk-throughs and patterns. steves-internet-guide.com+1
- Home Assistant community note — where to place bridge config with the Mosquitto add-on. Home Assistant Community
- Why bridging is used (industrial examples & patterns) — conceptual overview. Cedalo