MQTT Bridge

EMQ X bridges and forwards MQTT messages to MQTT Broker:

image

Config file for MQTT bridge plugin: etc/plugins/emqx_bridge_mqtt.conf

Configure MQTT Bridge

  1. ## Bridge address: node name for local bridge, host:port for remote
  2. bridge.mqtt.aws.address = 127.0.0.1:1883
  3. ## Protocol version of the bridge: mqttv3 | mqttv4 | mqttv5
  4. bridge.mqtt.aws.proto_ver = mqttv4
  5. ## Whether to enable bridge mode for mqtt bridge
  6. bridge.mqtt.aws.bridge_mode = true
  7. ## The ClientId of a remote bridge
  8. bridge.mqtt.aws.client_id = bridge_aws
  9. ## The Clean start flag of a remote bridge
  10. ## NOTE: Some IoT platforms require clean_start must be set to 'true'
  11. bridge.mqtt.aws.clean_start = true
  12. ## The username for a remote bridge
  13. bridge.mqtt.aws.username = user
  14. ## The password for a remote bridge
  15. bridge.mqtt.aws.password = passwd
  16. ## Bribge to remote server via SSL
  17. bridge.mqtt.aws.ssl = off
  18. ## PEM-encoded CA certificates of the bridge
  19. bridge.mqtt.aws.cacertfile = etc/certs/cacert.pem
  20. ## Client SSL Certfile of the bridge
  21. bridge.mqtt.aws.certfile = etc/certs/client-cert.pem
  22. ## Client SSL Keyfile of the bridge
  23. bridge.mqtt.aws.keyfile = etc/certs/client-key.pem
  24. ## SSL Ciphers used by the bridge
  25. bridge.mqtt.aws.ciphers = ECDHE-ECDSA-AES256-GCM-SHA384,ECDHE-RSA-AES256-GCM-SHA384
  26. ## Ciphers for TLS PSK
  27. ## Note that 'bridge.${BridgeName}.ciphers' and 'bridge.${BridgeName}.psk_ciphers' cannot be configured at the same time.
  28. ##
  29. ## See 'https://tools.ietf.org/html/rfc4279#section-2'.
  30. bridge.mqtt.aws.psk_ciphers = PSK-AES128-CBC-SHA,PSK-AES256-CBC-SHA,PSK-3DES-EDE-CBC-SHA,PSK-RC4-SHA
  31. ## Ping interval of a down bridge.
  32. bridge.mqtt.aws.keepalive = 60s
  33. ## TLS versions used by the bridge.
  34. bridge.mqtt.aws.tls_versions = tlsv1.2,tlsv1.1,tlsv1

Configure Topics MQTT Bridge Forwards and Subscribes

  1. ## Mountpoint of the bridge
  2. bridge.mqtt.aws.mountpoint = bridge/aws/${node}/
  3. ## Forward message topics
  4. bridge.mqtt.aws.forwards = topic1/#,topic2/#
  5. ## Subscriptions of the bridge topic
  6. bridge.mqtt.aws.subscription.1.topic = cmd/topic1
  7. ## Subscriptions of the bridge qos
  8. bridge.mqtt.aws.subscription.1.qos = 1
  9. ## Subscriptions of the bridge topic
  10. bridge.mqtt.aws.subscription.2.topic = cmd/topic2
  11. ## Subscriptions of the bridge qos
  12. bridge.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 EMQ X are forwarded to the remote MQTT Broker.

Subscription: Local EMQ X 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
  9. bridges add-subscription <Name> <Topic> <Qos> # Add bridge subscriptions topic

List Status of All Bridges

  1. $ ./bin/emqx_ctl bridges list
  2. name: emqx status: Stopped

Start Specified Bridge

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

Stop Specified Bridge

  1. $ ./bin/emqx_ctl bridges stop emqx
  2. Stop bridge successfully.

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 add-forwards emqx topic3/#
  2. Add-forward topic successfully.

Delete Forwarded Topic for Specified Bridge

  1. $ ./bin/emqx_ctl bridges del-forwards 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

  1. $ ./bin/emqx_ctl bridges del-subscription emqx cmd/topic3
  2. Del-subscription topic successfully.