MQTT Bridge
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 Topics MQTT Bridge Forwards and Subscribes
bridge.mqtt.aws.mountpoint = bridge/aws/${node}/
## Forward message topics
bridge.mqtt.aws.forwards = topic1/#,topic2/#
## Subscriptions of the bridge topic
bridge.mqtt.aws.subscription.1.topic = cmd/topic1
## Subscriptions of the bridge qos
bridge.mqtt.aws.subscription.1.qos = 1
## Subscriptions of the bridge topic
bridge.mqtt.aws.subscription.2.topic = cmd/topic2
## Subscriptions of the bridge qos
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.
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 bridges
bridges list # List bridges
bridges start <Name> # Start a bridge
bridges stop <Name> # Stop a bridge
bridges forwards <Name> # Show a bridge forward topic
bridges add-forward <Name> <Topic> # Add bridge forward topic
bridges del-forward <Name> <Topic> # Delete bridge forward topic
bridges subscriptions <Name> # Show a bridge subscriptions topic
Start Specified Bridge
$ ./bin/emqx_ctl bridges start emqx
Start bridge successfully.
Stop Specified Bridge
$ ./bin/emqx_ctl bridges stop emqx
List Forwarded Topic of Specified Bridge
$ ./bin/emqx_ctl bridges forwards emqx
topic: topic1/#
topic: topic2/#
Add 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 emqx
topic: cmd/topic1, qos: 1
topic: cmd/topic2, qos: 1
Add Subscriptions for Specified Bridge
$ ./bin/emqx_ctl bridges add-subscription emqx cmd/topic3 1
Add-subscription topic successfully.
Delete Subscriptions of Specified Bridge
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_bridge
broker.local_bridge.shared_subscription_strategy = local
## Subscribes bridge to shared topic