mqtt: receiving messages from an MQTT broker

You can use the mqtt() source to fetch messages from MQTT brokers.

The mqtt() source builds on the MQTT protocol , and uses its client and broker entities.

Prerequisites

Using the current implementation of the mqtt() source has the following prerequisites:

  • Installing the eclipse-paho-mqtt-c library.

  • Having a broker entity in a functional MQTT system.

Limitations

Using the mqtt() source of AxoSyslog has the following limitations:

  • You cannot use the mqtt() source without installing the eclipse-paho-mqtt-c library.

    For more information about how you can download and install the eclipse-paho-mqtt-c library, see Eclipse Paho on the Eclipse Foundation website.

  • The current implementation of the mqtt() source supports versions 3.1 and 3.1.1 of the MQTT protocol.

Declaration

Terminal window
source s_mqtt{
    mqtt(
        address("tcp://<hostname>:<port-number>")
        topic("<topic-name>")
    );
};

Starting with AxoSyslog version 4.7, mqtt() source automatically sets the ${MQTT_TOPIC} name-value pair for the messages it receives. This is useful when the name of the topic contains MQTT wildcards ($, +, #). For example:

Terminal window
log {
    source { mqtt(topic("#")); };
    destination { stdout(template("${MQTT_TOPIC} - ${MESSAGE}\n")); };
};

For the list of available optional parameters, see Options of the mqtt() source.

Example: Using the mqtt() source in your configuration

The following example illustrates an mqtt() source configured to fetch messages from the MQTT broker running on localhost:4444 using the test/test topic, and send them to the localhost:4445 address.

Terminal window
@version: current
@include "scl.conf"
source s_mqtt {
    mqtt(
        address("tcp://localhost:4444")
        topic("test/test")
    );
};
destination d_network {
    network(
        "localhost"
        port(4445)
    );
};
log {
    source(s_mqtt);
    destination(d_network);;
};
Last modified September 30, 2026: MQTT formatting fixes and restructuring (0639411c)