Skip to content

Mosquitto MQTT cluster bridging — connecting two brokers without a cluster mode

Bridging Mosquitto brokers for HA or multi-site MQTT — bridge directions, topic mapping, durability, and the operational pattern that replaces a real cluster.

Mosquitto does not have a built-in cluster mode. When clients need to publish to one broker and have those messages reach subscribers on another — for HA failover, multi-site replication, or to hand traffic from edge brokers to a regional aggregator — you use the bridge feature. This article is the bridge design we run for clients with MQTT fleets that have outgrown a single broker: how a bridge actually works, the direction-and-topic mapping you have to think about, the QoS and durability choices, and what bridging cannot do that a real cluster would.

How to verify

Check both brokers can reach each other on the bridge port (typically 8883 over TLS), and that the bridge user has been provisioned:

nc -vz broker-b.example.net 8883
mosquitto_pub -h broker-a.example.net -p 8883 -u admin -P PASS \
  -t '$SYS/broker/bridge/connection-state' -m test 2>&1 || true
sudo grep -E '^(connection|address|topic)' /etc/mosquitto/conf.d/*.conf

A bridge is configured on one side (typically called the “local” or initiating broker) and shows up under $SYS/broker/connection/<name>/state once active.

What’s happening

A Mosquitto bridge is the broker itself acting as an MQTT client of another broker. You declare a connection stanza in the config that says “from this broker, open an MQTT connection to that broker, authenticate with these credentials, and route these topics across in this direction.” The bridge is full-duplex: each topic mapping has a direction — out, in, or both.

Bridges solve three real problems:

  • HA fan-out — primary broker, secondary broker, devices configured with a fallback. Bridge the two so that when primary is down, devices reconnect to secondary and still see retained messages and pending QoS 1/2 deliveries. Not a true cluster — there is a brief gap during failover, and message ordering across the bridge is not guaranteed.
  • Multi-site aggregation — edge brokers at five sites bridge sensors/# “out” to a regional broker. Subscribers at the regional broker see a unified view of every site’s sensors. Bridge “in” goes the other way: send commands from regional broker down to all the edges.
  • Loose-coupled tiers — a public-facing MQTT broker bridges only specific topics into a private internal broker, providing a security boundary.

Bridges do not give you:

  • Synchronous replication. A publish to broker A is eventually visible on broker B, with the bridge’s latency and any retries. A crash on A between publish and bridge-forward loses that message (mitigatable with QoS 1/2 + persistence on the bridge connection, but never zero loss).
  • A unified client session. A client connecting to A then reconnecting to B is a new session from B’s perspective; QoS 1/2 in-flight messages on A do not migrate.
  • Load balancing. Bridges are about message routing, not connection distribution. A real load balancer (HAProxy in TCP mode) in front of two brokers handles connection sharing.

For client-facing HA, the canonical pattern is: two brokers, bridged in both directions for the topics that need it, and clients configured with a fallback address list. For multi-site aggregation, edge-to-central bridges with topic prefix mapping (sensors/ → sites/edge1/sensors/) keep the topic namespaces clean.

The procedure

  1. Provision a bridge user on each broker. On broker-b.example.net:

    sudo mosquitto_passwd /etc/mosquitto/passwd bridge-from-a
    sudo systemctl reload mosquitto

    Restrict permissions if you have an ACL file — bridge-from-a only needs publish/subscribe on the bridged topics.

  2. Add the bridge config on broker A at /etc/mosquitto/conf.d/02-bridge-to-b.conf:

    connection bridge-to-b
    address broker-b.example.net:8883
    
    remote_username bridge-from-a
    remote_password REPLACE_WITH_STRONG_PASS
    
    bridge_protocol_version mqttv50
    bridge_capath /etc/ssl/certs/
    bridge_insecure false
    
    notifications true
    notification_topic $SYS/bridges/bridge-to-b/state
    
    cleansession false
    start_type automatic
    restart_timeout 5 30
    idle_timeout 60
    keepalive_interval 60
    
    try_private false
    
    # topic mapping: pattern direction qos local-prefix remote-prefix
    topic sensors/# out 1 "" ""
    topic commands/# in 1 "" ""

    cleansession false is what makes the bridge durable — broker A’s bridge client remembers its subscriptions and offsets even across restarts of either broker.

  3. Mirror the config on broker B so the bridge is symmetric and either side can be primary:

    connection bridge-to-a
    address broker-a.example.net:8883
    
    remote_username bridge-from-b
    remote_password REPLACE_WITH_STRONG_PASS
    
    bridge_protocol_version mqttv50
    bridge_capath /etc/ssl/certs/
    bridge_insecure false
    
    cleansession false
    start_type automatic
    
    topic sensors/# out 1 "" ""
    topic commands/# in 1 "" ""

    Now both brokers see all sensors/ and commands/ traffic regardless of which one the publisher is connected to.

  4. Reload both brokers and check the bridge comes up:

    sudo systemctl reload mosquitto
    
    # on broker A
    mosquitto_sub -h localhost -t '$SYS/bridges/bridge-to-b/state' -v
    # should show "1" (connected)
    
    sudo journalctl -u mosquitto -n 30 --no-pager | grep -i bridge
  5. Test end-to-end. Publish on broker A, subscribe on broker B:

    # subscribe on broker-b
    mosquitto_sub -h broker-b.example.net -p 8883 \
      -u ops -P PASS --capath /etc/ssl/certs/ -t 'sensors/#' -v
    
    # publish on broker-a
    mosquitto_pub -h broker-a.example.net -p 8883 \
      -u app -P PASS --capath /etc/ssl/certs/ \
      -t 'sensors/edge1/temp' -m '21.4' -q 1

    The subscriber on B should see the message. The lag is typically sub-second on a healthy network.

  6. Configure devices with a fallback list. Most MQTT client libraries accept a list of addresses; on disconnect from primary, they cycle to the next. Set keepAlive short enough (30-60s) that failover detection is fast, and clean=false so QoS 1/2 in-flight messages are not lost on the secondary side.

  7. Wire monitoring. Mosquitto exposes bridge state on $SYS/bridges/<name>/state (1 connected, 0 disconnected). Subscribe to this from your monitoring tool, or use the mosquitto_exporter for Prometheus, and alert on bridge-down for more than 60 seconds.

Operational notes

  • A bridge is a normal MQTT client from the remote broker’s perspective; it counts toward max_connections, and its publishes count toward any per-user rate limits.
  • Topic mapping does not propagate retained messages by default; add bridge_attempt_unsubscribe true and the appropriate topic ... 1 mapping with attempt_subscribe semantics if you need the bridge to fetch retained messages on connect.
  • Loops are real — bridging # both ways creates an infinite echo. Always scope topic patterns explicitly, and use try_private false (the default in modern Mosquitto) which suppresses the loop-detection header but means you must be disciplined about scoping.
  • A bridge with cleansession true loses subscriptions on every reconnect, which silently drops messages during the gap. cleansession false and a stable client-id are what give you durability.
  • For 3+ brokers, do not build a full mesh — that becomes O(N^2) bridge connections. Use a hub-and-spoke topology with one regional aggregator and edges bridging only to it.

Stack Harbor stands up bridged MQTT topologies for clients with multi-site IoT footprints — edge brokers per site or per region, bridges configured under config management, fallback addresses generated into device configs, and dashboards that show bridge health alongside per-site message rates. This is the kind of design we run as part of our Multi-region environments practice.