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

    1. bridge.mqtt.aws.mountpoint = bridge/aws/${node}/
    2. ## Forward message topics
    3. bridge.mqtt.aws.forwards = topic1/#,topic2/#
    4. ## Subscriptions of the bridge topic
    5. bridge.mqtt.aws.subscription.1.topic = cmd/topic1
    6. ## Subscriptions of the bridge qos
    7. bridge.mqtt.aws.subscription.1.qos = 1
    8. ## Subscriptions of the bridge topic
    9. bridge.mqtt.aws.subscription.2.topic = cmd/topic2
    10. ## 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

    1. ./bin/emqx_ctl plugins load emqx_bridge_mqtt

    Bridge CLI Command

    1. $ cd emqx && ./bin/emqx_ctl bridges
    2. bridges list # List bridges
    3. bridges start <Name> # Start a bridge
    4. bridges stop <Name> # Stop a bridge
    5. bridges forwards <Name> # Show a bridge forward topic
    6. bridges add-forward <Name> <Topic> # Add bridge forward topic
    7. bridges del-forward <Name> <Topic> # Delete bridge forward topic
    8. bridges subscriptions <Name> # Show a bridge subscriptions topic

    Start Specified Bridge

    1. $ ./bin/emqx_ctl bridges start emqx
    2. Start bridge successfully.

    Stop Specified Bridge

    1. $ ./bin/emqx_ctl bridges stop emqx

    List Forwarded Topic of Specified Bridge

    1. $ ./bin/emqx_ctl bridges forwards emqx
    2. topic: topic1/#
    3. topic: topic2/#

    Add Forwarded Topic for Specified Bridge

    1. $ ./bin/emqx_ctl bridges del-forward emqx topic3/#
    2. Del-forward topic successfully.

    List Subscriptions of Specified Bridge

    1. $ ./bin/emqx_ctl bridges subscriptions emqx
    2. topic: cmd/topic1, qos: 1
    3. topic: cmd/topic2, qos: 1

    Add Subscriptions for Specified Bridge

    1. $ ./bin/emqx_ctl bridges add-subscription emqx cmd/topic3 1
    2. 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.

    1. ## Sets the local strategy
    2. ## for shared subscription group with name local_bridge
    3. broker.local_bridge.shared_subscription_strategy = local
    4. ## Subscribes bridge to shared topic