<Loggers> ... <AsyncLogger name="com.mulesoft.connectors.mqtt3" level="TRACE"/> ... </Loggers>
Troubleshoot MQTT Connector
To troubleshoot Anypoint Connector for MQTT (MQTT Connector), become familiar with the information about enabling verbose logging and interpreting commonly thrown messages.
To enable verbose logging on the connector, you need to activate logging for the connector and for the Eclipse Paho driver.
To enable verbose logging in the configuration file:
Access Anypoint Studio and navigate to the Package Explorer view.
Open your application’s project name.
log4j2.xmlfile inside the folder.
<AsyncLogger>tag inside the
Save your application changes.
Click the project name in Package Explorer and then click Run > Run As > Mule Application.
Eclipse Paho, the underlying driver for MQTT Connector uses Java Util Logging. If you want to see the driver’s log messages in the application’s log file, follow the next steps to provide your application with the latest
log4jcore module version by checking the version suffix in the file name of
For an embedded Mule runtime engine (Mule), find the folder that is similar to
Download the same version of
log4j-jul-2.xx.x.jarfrom the public Maven repository, for example, for Mule 4.3.0, it’s
In the Mule app, add the corresponding
java.util.loggingcategory as per the logging level mapping documented on the Apache Logging Services site, for example:
`<AsyncLogger name="org.eclipse.paho.client.mqttv3.logging.JSR47Logger" level="ALL"/>`
levelattribute, you must provide a Java Util Logging Level. Check the Apache Logging Services conversion table of Java Util Logging levels and its equivalent Log4j levels for further details.
Each broker has different mechanisms to configure logging. To set up a Mosquitto broker and configure logging levels, follow these steps:
Set up a Mosquitto broker by using the official Docker image. To do so, run the following command:
docker run -it -p 1883:1883 \
-v /your/local/path/mosquitto.log:/mosquitto/mosquitto.log \
-v /your/local/path/mosquitto.conf:/mosquitto/config/mosquitto.conf eclipse-mosquitto
By using this command, you supply the log file
mosquitto.log and the configuration file
mosquitto.logis a file for the broker to write log messages to.
mosquitto.confis the broker configuration file.
Set the desired log level in the
mosquitto.confconfiguration file, for example:
# Unencrypted MQTT over TCP # for listener at port 1883 listener 1883 allow_anonymous true # ================================================================= # Logging # ================================================================= # Route log messages to log file log_dest file /mosquitto/mosquitto.log # Types of messages to log. Use multiple log_type lines for logging # multiple types of messages. log_type debug log_type error log_type warning log_type notice log_type information
In the first two lines of the previous file you set up a listener in port 1883, with no authentication credentials required.
In the logging section you specify that the logs should be written to the
mosquitto.log file that you mounted, and that you want the broker to log messages of all levels.
You can add different listeners with different configurations, depending on what you need to test, for example:
per_listener_settings true # Unencrypted MQTT over TCP listener 1883 allow_anonymous true # Unencrypted MQTT over TCP listener 1884 password_file /mosquitto/config/mosquitto.passwd listener 8080 protocol websockets allow_anonymous true
In the previous file you configured 3 separate listeners:
On port 1883 you specified an endpoint that allows anonymous connections over MQTT.
On port 1884 you specified a password file where the broker expects to find the usernames and passwords for authentication.
On port 8080 you specified that you will admit websockets connections.
To set each individual listener with separate configurations you must first set the
Here is a list of common throw messages and how to interpret them:
The client became disconnected from the broker while attempting to publish a message.
The topic is invalid because, for example, the name is too short, too long, or contains invalid characters.
When publishing a message, an error occurred while reading or writing persistent data for reliable messaging.
An error occurred while attempting to publish a message.
All reconnection attempts failed.
An error occurred when the client timed out waiting to write messages to the server.