MQTT Bridge
VerneMQ can interface with other brokers (and itself) via MQTT bridges.
Bridges are a non-standard way (but de-facto standard) among MQTT broker implementations to connect two different MQTT brokers. Over a bridge, the topic tree of a remote broker becomes part of the topic tree on the local broker. VerneMQ bridges support plain TCP connections as well as SSL connections.
A bridge will be a point-to-point connection between 2 brokers, but can still forward all the messages from all cluster nodes to another cluster.
The VerneMQ bridge plugin currently forwards messages using MQTT protocol version 3.1.1. MQTT v5 messages will still be forwarded but be aware that metadata like user-defined properties will be dropped.
Enabling the bridge functionality
The MQTT bridge plugin (vmq_bridge
) is distributed with VerneMQ as an integrated plugin but is not enabled by default. After configuring the bridge as described below, make sure to enable the plugin by setting (vernemq.conf
):
See Managing plugins for more information on working with plugins.
Basic information on the configured bridges can be displayed on the admin CLI:
The vmq-admin bridge
command is only available when the bridge plugin is running.
Sample MQTT Bridge
To configure vmq_bridge
you need to edit the bridge section of the vernemq.conf
file to set endpoints and mapping topics. A brigde can push or pull messages, as defined in the topic pattern list.
Setup a bridge to a remote broker:
Different connection parameters can be set:
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:
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 usingin
, export messages to a remote broker usingout
or share messages inboth
directions. If this parameter is not defined, VerneMQ defaults toout
. The QoS level defines the publish/subscribe QoS level used for this topic and defaults to0
. (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:
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:
Restarting MQTT Bridges
MQTT Bridges that are initiated from the source broker (push bridges) are started when VerneMQ boots and finds a bridge configuration in the vernemq.conf
file. Sometimes it's useful to restart MQTT bridges without restarting a broker. This can be done by disabling, then enabling the vmq_bridge
plugin and manually calling the bridge start
command:
Last updated