Skip to content

MQTT over TCP Bridge

MQTT over TCP Bridging serves as a reliable communication strategy, leveraging the trustworthiness of the Transmission Control Protocol (TCP) to ensure the accuracy and integrity of MQTT messages during cross-network or cross-proxy communications. With the flexibility to adapt to various network environments and application scenarios, it plays a pivotal role in facilitating communication between Internet of Things (IoT) devices.

NanoMQ now supports MQTT over TCP bridging, enabling connections to the EMQX Enterprise MQTT IoT Access Platform.

Configure MQTT over TCP Bridge

NanoMQ comes with built-in support for MQTT over TCP bridging. Thus, after installing NanoMQ through any given method, you can immediately configure and enable MQTT over TCP bridging via the configuration file.

This section utilizes EMQ's free public bridge broker.emqx.io:1883 to establish MQTT over TCP data bridging. Insert the following content (in HOCON format) into the configuration file:

TIP

Using mqtt-tcp as the URL prefix signifies the use of TCP as the transport layer for MQTT.

Key Configuration Items

  • Remote broker address: bridges.mqtt.name.server
  • Array of remote topics to forward (supporting MQTT wildcard): bridges.mqtt.name.forwards
  • Array of remote topics to subscribe to (supporting MQTT wildcard): bridges.mqtt.name.subscription

If using Hocon version configuration items and NanoMQ version >= 0.19, you can either directly write the related configurations into nanomq.conf, or create a separate configuration file for bridging, such as nanomq_bridge.conf, and use HOCON's include syntax to reference this file in nanomq.conf:

Example:

bash
include "path/to/nanomq_bridge.conf"

To view more log data during runtime, you can set the log level log.level in the configuration file.

Start NanoMQ

When launching NanoMQ, use the --conf command line option to specify the path to the configuration file (If the configuration file is already located in the system path /etc/nanomq.conf, there's no need to specify it in the command line).

TIP

If you enabled SQLite feature, NanoMQ will automatically flush cached messages into disk when network is disconnected. NanoMQ will resend cached messages once bridging connection is restored. But each cached message will be resent in a certain interval to avoid bandwidth exhaustion.

Test the Bridge

This section will guide you in testing the newly established MQTT data bridge using the MQTTX Client Tool. We will create two connections, one to NanoMQ and the other to the MQTT data bridge, to verify the message sending and receiving services of both NanoMQ and the data bridge.

Client connecting NanoMQ

Connect to NanoMQ

Client connecting MQTT bridge

Connect to Public Broker

Verify messages are forwarded from NanoMQ to MQTT bridge

On your client connecting the MQTT bridge, MQTTbridge in this example, subscribe to the fwd/# topic.

On your client connecting NanoMQ, NanoMQTest in this example, publish a message to the topic1 topic, for example, Hello from NanoMQ

Verify that you received the message that was published from the local broker.

message from nanomq

Verify subscribed messages are received by NanoMQ from MQTT bridge

On your client connecting NanoMQ, NanoMQTest in this example, subscribe to the topic3 topic.

On your client connecting the MQTT bridge, MQTTbridge in this example, publish a message to the cmd/topic3 topic, for example, Hello from broker.emqx.io

Verify that you received the message that was published from broker.emqx.io.

message from broker

If you're interested in evaluating the performance of MQTT over QUIC bridging, you can conduct a benchmark test. Please refer to the guide available at Toolkit - Bench for detailed instructions.