# Bridge Data into MQTT Broker
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 set up MQTT bridges in the 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 remote bridge.mqtt.aws.address = 127.0.0.1:1883 ## Protocol version of the bridge: mqttv3 | mqttv4 | mqttv5 bridge.mqtt.aws.proto_ver = mqttv4 ## Whether to enable bridge mode for mqtt bridge bridge.mqtt.aws.bridge_mode = true ## The ClientId of a remote bridge bridge.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 bridge bridge.mqtt.aws.username = user ## The password for a remote bridge bridge.mqtt.aws.password = passwd ## Bribge to remote server via SSL bridge.mqtt.aws.ssl = off ## PEM-encoded CA certificates of the bridge bridge.mqtt.aws.cacertfile = etc/certs/cacert.pem ## Client SSL Certfile of the bridge bridge.mqtt.aws.certfile = etc/certs/client-cert.pem ## Client SSL Keyfile of the bridge bridge.mqtt.aws.keyfile = etc/certs/client-key.pem ## SSL Ciphers used by the bridge bridge.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' and 'https://tools.ietf.org/html/rfc4279#section-4'. bridge.mqtt.aws.psk_ciphers = PSK-AES256-GCM-SHA384,PSK-AES128-GCM-SHA256,PSK-AES256-CBC-SHA384,PSK-AES256-CBC-SHA,PSK-AES128-CBC-SHA256,PSK-AES128-CBC-SHA,RSA-PSK-AES256-GCM-SHA384,RSA-PSK-AES256-CBC-SHA384,RSA-PSK-AES128-GCM-SHA256,RSA-PSK-AES128-CBC-SHA256,RSA-PSK-AES256-CBC-SHA,RSA-PSK-AES128-CBC-SHA,RSA-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
Copied!
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Configure Topics MQTT Bridge Forwards and Subscribes
## Mountpoint of the bridge 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 bridge.mqtt.aws.subscription.2.qos = 1
Copied!
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 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
Copied!
# 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 bridges add-subscription <Name> <Topic> <Qos> # Add bridge subscriptions topic
Copied!
2
3
4
5
6
7
8
9
# List Status of All Bridges
$ ./bin/emqx_ctl bridges list name: emqx status: Stopped
Copied!
2
# Start Specified Bridge
$ ./bin/emqx_ctl bridges start emqx Start bridge successfully.
Copied!
2
# Stop Specified Bridge
$ ./bin/emqx_ctl bridges stop emqx Stop bridge successfully.
Copied!
2
# List Forwarded Topic of Specified Bridge
$ ./bin/emqx_ctl bridges forwards emqx topic: topic1/# topic: topic2/#
Copied!
2
3
# Add Forwarded Topic for Specified Bridge
$ ./bin/emqx_ctl bridges add-forward emqx topic3/# Add-forward topic successfully.
Copied!
2
# Delete Forwarded Topic for Specified Bridge
$ ./bin/emqx_ctl bridges del-forward emqx topic3/# Del-forward topic successfully.
Copied!
2
# List Subscriptions of Specified Bridge
$ ./bin/emqx_ctl bridges subscriptions emqx topic: cmd/topic1, qos: 1 topic: cmd/topic2, qos: 1
Copied!
2
3
# Add Subscriptions for Specified Bridge
$ ./bin/emqx_ctl bridges add-subscription emqx cmd/topic3 1 Add-subscription topic successfully.
Copied!
2
# Delete Subscriptions of Specified Bridge
$ ./bin/emqx_ctl bridges del-subscription emqx cmd/topic3 Del-subscription topic successfully.
Copied!
2
# 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 bridge.mqtt.my_bridge.forwards = $share/local_bridge/topic1/#
Copied!
2
3
4
5
6
- 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