HiveMQ MQTT 5 Client Not Connecting to MQTT 3 Broker

I am creating HiveMQ MQTT 5 async client which I am trying to connect to the MQTT broker v3 but my client is not connecting to the broker and below error messages are what I see in my HiveMQ MQTT broker’s event.log file -

2023-12-04 13:23:10,099 - Client ID: UNKNOWN, IP:172.17.0.1 was disconnected. reason: Incorrect CONNECT client id length.

Can somebody please confirm if HiveMQ MQTT 5 client library is compatible with MQTT 3 and 3.1.1 brokers?

Hi hussainbadshah,

Can somebody please confirm if HiveMQ MQTT 5 client library is compatible with HiveMQ V3 brokers?

(Correction)
HiveMQ (Broker) version 3 supports MQTT 3.1 and MQTT 3.1.1 and not MQTT 5.
HiveMQ (Broker) version 4 supports MQTT 3.1 and MQTT 3.1.1 and MQTT 5.

Incorrect CONNECT client id length > This error signifies that the client id length used might not be the correct specification for MQTT 3.x broker.
From official specification MQTT Version 3.1.1

The Server MUST allow ClientIds which are between 1 and 23 UTF-8 encoded bytes in length, and that contain only the characters. “0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ” [MQTT-3.1.3-5].

In case of HiveMQ, you can use either the default length or increase it as follows No limits for MQTT clients identifiers

By default, HiveMQ uses the standard MQTT limit of 23 characters to assure MQTT specification compatibility. If you are sure you want to change this behaviour, change the property global.maxClientIdLength in the configuration.properties file of your HiveMQ installation to a number you like to use.

Hope this helps.

@hivemq-support Thank you for the explanation with necessary details but I’m still getting the same error even after configuring the clientID = “client1” which is just 7 characters. Below are the details:

  • Docker image for HiveMQ MQTT 3 broker: hivemq/hivemq3:3.4.7

  • The default “config.xml” that comes with this image:

<?xml version="1.0"?>

<listeners>
    <tcp-listener>
        <port>1883</port>
        <bind-address>0.0.0.0</bind-address>
    </tcp-listener>
</listeners>
<web-ui>
    <listeners>
        <http>
            <port>8080</port>
            <bind-address>0.0.0.0</bind-address>
        </http>
    </listeners>
</web-ui>

What can I do or check to debug this issue further?

Hi @hussainbadshah,

HiveMQ 3 only knows MQTT 3 / 3.1.1. You will need to use HiveMQ 4 for MQTT 5 support.

So you will not be able to connect any MQTT 5 client to HiveMQ 3.

Also note that HiveMQ 3 is no longer supported.

Greetings,
Michael from the HiveMQ team

1 Like

Hi @michael_w if you check the following website: Implementing MQTT in Java.

Under the heading: " Using the HiveMQ MQTT Client Library for Java" it clearly states that the HiveMQ MQTT Java Client support both MQTT 5.0 and MQTT 3 protocols. Based on the information collected from the official docs of HiveMQ MQTT Client library only, we proceeded with HiveMQ MQTT 5 Client, thinking it supports both 3 and 3.1.1 brokers as well.

Hi @hussainbadshah,

Based on the information collected from the official docs of HiveMQ MQTT Client library only, we proceeded with HiveMQ MQTT 5 Client, thinking it supports both 3 and 3.1.1 brokers as well.

The HiveMQ Java clients supports MQTT 5 and MQTT 3.1.1 as stated in the README.md first sentence.

MQTT 5.0 and 3.1.1 compatible and feature-rich high-performance Java client library with different API flavours and backpressure support.

HiveMQ (Broker) version 3 supports MQTT 3.1 and MQTT 3.1.1 and not MQTT 5.

HiveMQ (Broker) version 4 supports MQTT 3.1 and MQTT 3.1.1 and MQTT 5.

If you now like to connect with the HiveMQ Java client to a HiveMQ 3 broker that does not support MQTT 5 you will need to tell the client to create an MQTT 3 connection. (As the CONNECT packet is slightly different and the HiveMQ 3 Broker does not know how to handle an MQTT 5 style CONNECT packet.)

To do this you create the HiveMQ Java client in the MQTT 3 flavor as documented here:

Mqtt3Client client = Mqtt3Client.builder()
        .identifier(UUID.randomUUID().toString())
        .serverHost("<your broker address>")
        .build();

I hope this helps

All the best
Georg

1 Like

Thank you for all the information.

Warm Regards
Hussain