Contact Us 1-800-596-4880

Troubleshooting MQTT Connector

To troubleshoot Anypoint Connector for MQTT (MQTT Connector), become familiar with the information about enabling verbose logging and interpreting commonly thrown messages.

Enable Verbose Logging

To enable verbose logging on the connector, you need to activate logging for the connector and for the Eclipse Paho driver.

Enable Verbose Logging for MQTT Connector

To enable verbose logging in the configuration file:

  1. Access Anypoint Studio and navigate to the Package Explorer view.

  2. Open your application’s project name.

  3. Open the src/main/resources path folder.

  4. Open the log4j2.xml file inside the folder.

  5. Add an <AsyncLogger> tag inside the <Loggers> tag:

    			<Loggers>
    				...
    				<AsyncLogger name="com.mulesoft.connectors.mqtt3" level="TRACE"/>
    				...
    			</Loggers>
  6. Save your application changes.

  7. Click the project name in Package Explorer and then click Run > Run As > Mule Application.

Enable Verbose Logging for Eclipse Paho Driver

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 log4j-jul-2.xx.x.jar version:

  1. Identify the log4j core module version by checking the version suffix in the file name of log4j-core-2.xx.x.jar in {MULE_HOME}/lib/boot.

    For an embedded Mule runtime engine (Mule), find the folder that is similar to {AnypointStudio Folder}/Contents/Eclipse/plugins/org.mule.tooling.server.4.3.0.ee_7.3.5.202005112043/mule/lib/boot

  2. Download the same version of log4j-jul-2.xx.x.jar from the public Maven repository, for example, for Mule 4.3.0, it’s log4j-jul-2.13.1.jar.

  3. Put the log4j-jul-2.xx.x.jar into {MULE_HOME}/lib/boot.

  4. In the Mule app, add the corresponding java.util.logging category 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"/>`

    For the level attribute, 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.

Enable Verbose Logging for Mosquitto Broker

Each broker has different mechanisms to configure logging. To set up a Mosquitto broker and configure logging levels, follow these steps:

  1. 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.conf.

  • The mosquitto.log is a file for the broker to write log messages to.

  • The mosquitto.conf is the broker configuration file.

  1. Set the desired log level in the mosquitto.conf configuration 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 per_listener_settings true.

Understand Common Throws

Here is a list of common throw messages and how to interpret them:

  • MQTT3:CONNECTIVITY

    The client became disconnected from the broker while attempting to publish a message.
  • MQTT3:INVALID_TOPIC

    The topic is invalid because, for example, the name is too short, too long, or contains invalid characters.
  • MQTT3:PERSISTENCE

    When publishing a message, an error occurred while reading or writing persistent data for reliable messaging.
  • MQTT3:PUBLISH

    An error occurred while attempting to publish a message.
  • MQTT3:RETRY_EXHAUSTED

    All reconnection attempts failed.
  • MQTT3:WRITE_TIMEOUT

    An error occurred when the client timed out waiting to write messages to the server.
View on GitHub