- MQTT Bridge
- Configure MQTT Bridge
- Configure Topics MQTT Bridge Forwards and Subscribes
- Description of Topics MQTT Bridge Forwards and Subscribes
- Enable MQTT Bridge
- Bridge CLI Command
- List Status of All Bridges
- Start Specified Bridge
- Stop Specified Bridge
- List Forwarded Topic of Specified Bridge
- Add Forwarded Topic for Specified Bridge
- Delete Forwarded Topic for Specified Bridge
- List Subscriptions of Specified Bridge
- Add Subscriptions for Specified Bridge
- Delete Subscriptions of Specified Bridge
- Use shared local subscription
MQTT Bridge
TIP
After EMQX version 3.1, a powerful rule engine is introduced to replace plug-ins. It is recommended that you use it. See Bridge data to MQTT to setup mqtt bridges in rule engine.
EMQX bridges and forwards MQTT messages to MQTT Broker:

Config file for MQTT bridge plugin: etc/plugins/emqx_bridge_mqtt.conf
Configure MQTT Bridge
## Bridge address: node name for local bridge, host:port for remotebridge.mqtt.aws.address = 127.0.0.1:1883## Protocol version of the bridge: mqttv3 | mqttv4 | mqttv5bridge.mqtt.aws.proto_ver = mqttv4## Whether to enable bridge mode for mqtt bridgebridge.mqtt.aws.bridge_mode = true## The ClientId of a remote bridgebridge.mqtt.aws.clientid = bridge_aws## The Clean start flag of a remote bridge## NOTE: Some IoT platforms require clean_start must be set to 'true'bridge.mqtt.aws.clean_start = true## The username for a remote bridgebridge.mqtt.aws.username = user## The password for a remote bridgebridge.mqtt.aws.password = passwd## Bribge to remote server via SSLbridge.mqtt.aws.ssl = off## PEM-encoded CA certificates of the bridgebridge.mqtt.aws.cacertfile = etc/certs/cacert.pem## Client SSL Certfile of the bridgebridge.mqtt.aws.certfile = etc/certs/client-cert.pem## Client SSL Keyfile of the bridgebridge.mqtt.aws.keyfile = etc/certs/client-key.pem## SSL Ciphers used by the bridgebridge.mqtt.aws.ciphers = ECDHE-ECDSA-AES256-GCM-SHA384,ECDHE-RSA-AES256-GCM-SHA384## Ciphers for TLS PSK## Note that 'bridge.${BridgeName}.ciphers' and 'bridge.${BridgeName}.psk_ciphers' cannot be configured at the same time.#### See 'https://tools.ietf.org/html/rfc4279#section-2'.bridge.mqtt.aws.psk_ciphers = PSK-AES128-CBC-SHA,PSK-AES256-CBC-SHA,PSK-3DES-EDE-CBC-SHA,PSK-RC4-SHA## Ping interval of a down bridge.bridge.mqtt.aws.keepalive = 60s## TLS versions used by the bridge.bridge.mqtt.aws.tls_versions = tlsv1.2,tlsv1.1,tlsv1
Configure Topics MQTT Bridge Forwards and Subscribes
## Mountpoint of the bridgebridge.mqtt.aws.mountpoint = bridge/aws/${node}/## Forward message topicsbridge.mqtt.aws.forwards = topic1/#,topic2/### Subscriptions of the bridge topicbridge.mqtt.aws.subscription.1.topic = cmd/topic1## Subscriptions of the bridge qosbridge.mqtt.aws.subscription.1.qos = 1## Subscriptions of the bridge topicbridge.mqtt.aws.subscription.2.topic = cmd/topic2## Subscriptions of the bridge qosbridge.mqtt.aws.subscription.2.qos = 1
Description of Topics MQTT Bridge Forwards and Subscribes
Mountpoint: Mountpoint is used to prefix of topic when forwarding a message, this option must be used with forwards. Forwards the message whose topic is “sensor1/hello”, its topic will change to “<bridge/aws/emqx1@192.168.1.1/sensor1/hello>” when it reaches the remote node.
Forwards: Messages forwarded to forwards specified by local EMQX are forwarded to the remote MQTT Broker.
Subscription: Local EMQX synchronizes messages from a remote MQTT Broker to local by subscribing to the topic of the remote MQTT Broker.
Enable MQTT Bridge
./bin/emqx_ctl plugins load emqx_bridge_mqtt
Bridge CLI Command
$ cd emqx && ./bin/emqx_ctl bridgesbridges list # List bridgesbridges start <Name> # Start a bridgebridges stop <Name> # Stop a bridgebridges forwards <Name> # Show a bridge forward topicbridges add-forward <Name> <Topic> # Add bridge forward topicbridges del-forward <Name> <Topic> # Delete bridge forward topicbridges subscriptions <Name> # Show a bridge subscriptions topicbridges add-subscription <Name> <Topic> <Qos> # Add bridge subscriptions topic
List Status of All Bridges
$ ./bin/emqx_ctl bridges listname: emqx status: Stopped
Start Specified Bridge
$ ./bin/emqx_ctl bridges start emqxStart bridge successfully.
Stop Specified Bridge
$ ./bin/emqx_ctl bridges stop emqxStop bridge successfully.
List Forwarded Topic of Specified Bridge
$ ./bin/emqx_ctl bridges forwards emqxtopic: topic1/#topic: topic2/#
Add Forwarded Topic for Specified Bridge
$ ./bin/emqx_ctl bridges add-forward emqx topic3/#Add-forward topic successfully.
Delete Forwarded Topic for Specified Bridge
$ ./bin/emqx_ctl bridges del-forward emqx topic3/#Del-forward topic successfully.
List Subscriptions of Specified Bridge
$ ./bin/emqx_ctl bridges subscriptions emqxtopic: cmd/topic1, qos: 1topic: cmd/topic2, qos: 1
Add Subscriptions for Specified Bridge
$ ./bin/emqx_ctl bridges add-subscription emqx cmd/topic3 1Add-subscription topic successfully.
Delete Subscriptions of Specified Bridge
$ ./bin/emqx_ctl bridges del-subscription emqx cmd/topic3Del-subscription topic successfully.
Use shared local subscription
When using EMQX in cluster mode, bridge is started on every node. This makes each message bridged to the target N times (where N is a number of started nodes in cluster). To avoid this, one can use shared subscription mechanism which ensures that only one of bridges receives the message.
## Sets the local strategy## for shared subscription group with name local_bridgebroker.local_bridge.shared_subscription_strategy = local## Subscribes bridge to shared topicbridge.mqtt.my_bridge.forwards = $share/local_bridge/topic1/#
