MQTT to MQTT

Description

ezvpn-mqtt-mqtt-multi subscribes to multiple MQTT broker and publishes all events to other MQTT servers.

It can:

  • Subscribe multiple topics in multiple MQTT Brokers
  • Publish messages using multiple topics in multiple MQTT Brokers

Generic MQTT Multi Schema

How to use it

ezvpn-mqtt-mqtt-multi is a Docker container container based on Eclipse Mosquitto. To use, install it along with ezvpn-mqtt and a destination MQTT broker. You can anyway point the source broker to any other address.

This containers support bidirectional connections.

To configure it only one environment variable must be provided: MQTT_CFG

MQTT_CFG is a string representing a JSON object, describing the MQTT Brokers definitions, subscribe topics, and publish topics.

The working example below represents an oversimplified case with:

  • two MQTT Brokers (mqtt1 and mqtt2)
  • one subscription to topic1 in mqtt1 broker that publish the incoming messages on mqtt2 broker in topic2
  • one subscription to topic12/# in mqtt2 broker that publish the incoming messages on mqtt1 broker using same topic coming from mqtt2
{
    "mqtts": [
        {
            "name": "mqtt1",
            "host": "ezvpn-mqtt"
        },
        {
            "name": "mqtt2",
            "host": "192.168.52.5",
            "port": 1883,
            "username": "mosquitto",
            "password": "mosquitto",
            "qos2": true,
            "retryOnError": true
        }
    ],
    "forwards": [
        {
            "from": {
                "mqtt": "mqtt1",
                "topic": "topic1"
            },
            "to": {
                "mqtt": "mqtt2",
                "topic": "topic2"
            }
        },
        {
            "from": {
                "mqtt": "mqtt2",
                "topic": "topic12/#"
            },
            "to": {
                "mqtt": "mqtt1"
            }
        }
    ]
}

Mapping configuration (MQTT_CFG)

The JSON object has 2 array fields:

{
    "mqtts": [],
    "forwards": []
}

mqtts (required): contains the list of the available MQTT brokers.

forwards (required): contains the list of subscribe and publish topics.

mqtts

mqtts is an array of objects, representing the available MQTT brokers. The mqtts array cannot be empty.

Each mqtts is represented by the following object:

{
    "name": "<MQTT broker name>",
    "host": "<MQTT address>",
    "port": <MQTT port>,
    "username": "<authentication username>",
    "password": "<authentication password>",
    "qos2": <true or false>,
    "retryOnError": <true or false>
}
  • name and host are required.

  • port if not defined defaults to 1883

  • username MQTT broker authentication username if requested

  • password MQTT broker authentication password if requested

  • qos2 boolean type, enable qos2 on MQTT, defaults to false

  • retryOnError: boolean type, retry to send messages if error occurred. Defaults to false

forwards

forwards is an array of objects, representing the subscribe and publish topics. The forwards array cannot be empty.

Each forwards is represented by the following object:

{
    "from": {
        "mqtt": "<a MQTT defined in the mqtts section>",
        "topic": "<subscribe topic>"
    },
    "to": {
        "mqtt": "<a MQTT defined in the mqtts section>",
        "topic": "<publish topic>"
    }
}

from definition

To manage messages from the MQTT broker (subscribe)

  • mqtt: a MQTT source defined in the mqtts section Required
  • topic: topic to subscribe. You can define a single topic or use special characters + and # in the string. Required

to definition

To manage messages to the MQTT broker (publish)

  • mqtt: a MQTT destination defined in the mqtts section Required
  • topic: topic to publish. You can define only a single topic. If not defined, messages are forwarded using the source topics.

All messages received on from definition are forwarded to the to definition in raw mode.

Environment variables

When you start the ezvpn-mqtt-mqtt-multi container, you can adjust the instance's configuration by passing one or more environment variables to the docker run command.

  • MQTT_CFG: MQTT forward configuration

Docker container details

Image: us-central1-docker.pkg.dev/ez-shared/iohub/iohub-mqtt-mqtt-multi

Supported architecture: amd64

Changelog

v1.1.0
  • bug fix
  • retryOnError moved to MQTT definition
v1.0.9
  • added destination topic optional equal to the source
v1.0.8
  • added missing modules
v1.0.7
  • First Release