MQTT Bridge
Bridges are a non-standard way, although kind of a de-facto standard among MQTT broker implementations, to connect two different MQTT brokers to eachother. This allows for example that a topic tree of a remote broker becomes part of the topic tree on the local broker. VerneMQ supports plain TCP connections as well as SSL connections.

Enabling the bridge functionality

in VerneMQ the bridge is distributed with VerneMQ as a plugin and is not enabled by default. After configuring the bridge as described below, make sure to enable the plugin by setting:
1
plugins.vmq_bridge = on
Copied!
See Managing plugins for more information on working with plugins.
When the plugin is enabled a simple status interface is available:
1
$ vmq-admin bridge show
2
+-----------------+-----------+----------+-------------------+
3
| endpoint |buffer size|buffer max|buffer dropped msgs|
4
+-----------------+-----------+----------+-------------------+
5
|192.168.1.10:1883| 0 | 0 | 0 |
6
+-----------------+-----------+----------+-------------------+
Copied!

Sample MQTT Bridge

Setup a bridge to a remote broker:
1
vmq_bridge.tcp.br0 = 192.168.1.12:1883
Copied!
Different connection parameters can be set:
1
# use a clean session (defaults to 'off')
2
vmq_bridge.tcp.br0.cleansession = off | on
3
4
# set the client id (defaults to 'auto', which generates one)
5
vmq_bridge.tcp.br0.client_id = auto | my_bridge_client_id
6
7
# set keepalive interval (defaults to 60 seconds)
8
vmq_bridge.tcp.br0.keepalive_interval = 60
9
10
# set the username and password for the bridge connection
11
vmq_bridge.tcp.br0.username = my_bridge_user
12
vmq_bridge.tcp.br0.password = my_bridge_pwd
13
14
# set the restart timeout (defaults to 10 seconds)
15
vmq_bridge.tcp.br0.restart_timeout = 10
16
17
# VerneMQ indicates other brokers that the connection
18
# is established by a bridge instead of a normal client.
19
# This can be turned off if needed:
20
vmq_bridge.tcp.br0.try_private = off
21
22
# Set the maximum number of outgoing messages the bridge will buffer
23
# while not connected to the remote broker. Messages published while
24
# the buffer is full are dropped. A value of 0 means buffering is
25
# disabled.
26
vmq_bridge.tcp.br0.max_outgoing_buffered_messages = 100
Copied!
Define the topics the bridge should incorporate in its local topic tree (by subscribing to the remote), or the topics it should export to the remote broker (by publishing to the remote). We share a similar configuration syntax to that used by the Mosquitto broker:
1
topic [[[ out | in | both ] qos-level] local-prefix remote-prefix]
Copied!
topic defines a topic pattern that is shared between the two brokers. Any topics matching the pattern (which may include wildcards) are shared. The second parameter defines the direction that the messages will be shared in, so it is possible to import messages from a remote broker using in, export messages to a remote broker using out or share messages in both directions. If this parameter is not defined, VerneMQ defaults to out. The QoS level defines the publish/subscribe QoS level used for this topic and defaults to 0. (Source: mosquitto.conf)
The local-prefix and remote-prefix can be used to prefix incoming or outgoing publish messages.
Currently the # wildcard is treated as a comment from the configuration parser, please use * instead.
A simple example:
1
# share messages in both directions and use QoS 1
2
vmq_bridge.tcp.br0.topic.1 = /demo/+ both 1
3
4
# import the $SYS tree of the remote broker and
5
# prefix it with the string 'remote'
6
vmq_bridge.tcp.br0.topic.2 = $SYS/* in remote
Copied!

Sample MQTT Bridge that uses SSL/TLS

SSL bridges support the same configuration parameters as TCP bridges, but need further instructions for handling the SSL specifics:
1
# define the CA certificate file or the path to the
2
# installed CA certificates
3
vmq_bridge.ssl.br0.cafile = cafile.crt
4
#or
5
vmq_bridge.ssl.br0.capath = /path/to/cacerts
6
7
# if the remote broker requires client certificate authentication
8
vmq_bridge.ssl.br0.certfile = /path/to/certfile.pem
9
# and the keyfile
10
vmq_bridge.ssl.br0.keyfile = /path/to/keyfile
11
12
# disable the verification of the remote certificate (defaults to 'off')
13
vmq_bridge.ssl.br0.insecure = off
14
15
# set the used tls version (defaults to 'tlsv1.2')
16
vmq_bridge.ssl.br0.tls_version = tlsv1.2
Copied!