Skip to content

MQTT Bridge Route Implementation in Coreflux MQTT Broker

1. Overview

The MQTT Bridge Route implementation in the Coreflux MQTT broker enables the exchange of information between brokers.

This functionality is achieved by configuring routes that define the source and destination brokers, along with topic mappings to facilitate message flow.

2. Key Features

  • Bridging between MQTT brokers using TLS/SSL, with an option for mTLS, to ensure secure communication.
  • Support for wildcards (+ and #) in topic mappings.
  • Flexible route configuration with optional self-reference to the serving broker.

3. Route Configuration

A route can be configured using the addRoute command. Below are two examples of route configurations:

3.1 Example Explicit Broker Address Configuration

-addRoute DEFINE ROUTE MqttBridge2Route WITH TYPE MQTT_BRIDGE
    ADD SOURCE_CONFIG
        WITH BROKER_ADDRESS "172.99.186.202"
        WITH BROKER_PORT '8883'
        WITH CLIENT_ID "LocalClient"
        WITH USERNAME "root"
        WITH PASSWORD "coreflux"
        WITH RECONNECTION_RETRIES 20
        WITH USE_TLS true
        WITH ALLOW_UNTRUSTED_CERTS false
        WITH SERVER_CA_CERT_PATH "/path/to/rootCA.pem"
        WITH CLIENT_CERT_PATH "/path/to/cert/client_combined.pem"
    ADD DESTINATION_CONFIG
        WITH BROKER_ADDRESS "iot.coreflux.cloud"
        WITH BROKER_PORT '1883'
        WITH CLIENT_ID "RemoteClient"
        WITH USERNAME ""
        WITH PASSWORD ""
    ADD MAPPING sensors
        WITH SOURCE_TOPIC "sensor/value"
        WITH DESTINATION_TOPIC "sensor/from/source"
        WITH DIRECTION "out"

3.2 Example Using Self Reference

-addRoute DEFINE ROUTE MqttBridge2Route WITH TYPE MQTT_BRIDGE
    ADD SOURCE_CONFIG
        WITH BROKER SELF
    ADD DESTINATION_CONFIG
        WITH BROKER_ADDRESS "iot.coreflux.cloud"
        WITH BROKER_PORT '1883'
        WITH CLIENT_ID "RemoteClient"
        WITH USERNAME ""
        WITH PASSWORD ""
    ADD MAPPING temperature
        WITH SOURCE_TOPIC "room/temp"
        WITH DESTINATION_TOPIC "source/room/temp"
        WITH DIRECTION "out"

3.3 Explanation of Configuration Options

General Configuration

  • BROKER_ADDRESS: Specifies the address of the source or destination broker.
  • BROKER_PORT: Port number for the broker connection.
  • CLIENT_ID: Identifier for the MQTT client.
  • USERNAME / PASSWORD: Authentication credentials for connecting to the broker.
  • RECONNECTION_RETRIES: Specifies the maximum number of reconnection attempts in case the client loses connection to the broker.

Security Configuration

  • USE_TLS: Enables secure communication.
  • ALLOW_UNTRUSTED_CERTS: Specifies whether to allow untrusted certificates (useful for development).
  • SERVER_CA_CERT_PATH: Path to the Certificate Authority (CA) certificate.
  • CLIENT_CERT_PATH: Path to the client certificate for mutual TLS.
  • CLIENT_CERT_PASS: Password used to access the token certificate specified in CLIENT_CERT_PATH.

Topic Configuration

  • SOURCE_TOPIC / DESTINATION_TOPIC: Defines topic mappings between brokers.
  • DIRECTION: Specifies the message flow (out, in, or both).

Using Self Reference

  • BROKER SELF: Indicates that the source broker is the one serving as the MQTT server.When SELF is enabled, all other configuration parameters (e.g., BROKER_ADDRESS, BROKER_PORT, USERNAME, PASSWORD, etc.) are ignored and should not be included in the configuration.

4 Wildcard Implementation in Topics

4.1 Supported Wildcards

  • +: Matches a single level in the topic hierarchy.
  • #: Matches all subsequent levels in the topic hierarchy.

4.1.1 Example of '+'

For the source topic room/+/status and destination topic results/+/monitoring/source:

  • A message published to room/sensor1/status will be routed to results/sensor1/monitoring/source.
  • A message published to room/sensor2/status will be routed to results/sensor2/monitoring/source.

4.1.2Example of '#'

For the source topic room/# and destination topic results/#:

  • A message published to room/sensor1/status will be routed to results/sensor1/status.
  • A message published to room/living/temp/humidity will be routed to results/living/temp/humidity.
  • A message published to room/basement will be routed to results/basement.

5 Conclusion

The MQTT Bridge Route in Coreflux MQTT Broker provides a robust solution for bridging brokers.

Its support for secure communication, topic mappings with wildcards, and self-referencing capabilities makes it versatile for various use cases.