# HiveMQ MQTT 5 Client Not Connecting to MQTT 3 Broker

**URL:** <https://community.hivemq.com/t/hivemq-mqtt-5-client-not-connecting-to-mqtt-3-broker/2537>\
**Category:** HiveMQ Client Library\
**Created:** [December 4, 2023, 1:25pm UTC](https://community.hivemq.com/t/hivemq-mqtt-5-client-not-connecting-to-mqtt-3-broker/2537 "2023-12-04T13:25:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![hussainbadshah](https://avatars.discourse-cdn.com/v4/letter/h/a698b9/32.png) [@hussainbadshah](https://community.hivemq.com/u/hussainbadshah)\
**Post date:** [December 4, 2023, 1:25pm UTC](https://community.hivemq.com/t/hivemq-mqtt-5-client-not-connecting-to-mqtt-3-broker/2537/1 "2023-12-04T13:25:00Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![hivemq-support](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.hivemq.com/hivemq-support/32/357_2.png) [@hivemq-support](https://community.hivemq.com/u/hivemq-support)\
**Post date:** [December 5, 2023, 9:06am UTC](https://community.hivemq.com/t/hivemq-mqtt-5-client-not-connecting-to-mqtt-3-broker/2537/2 "2023-12-05T09:06:42Z")

</div>

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](https://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc385349242)

> 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](https://www.hivemq.com/article/supporting-mqtt-client-identifiers-23-characters/)

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

---

<div class="post-metadata">

**Author:** ![hussainbadshah](https://avatars.discourse-cdn.com/v4/letter/h/a698b9/32.png) [@hussainbadshah](https://community.hivemq.com/u/hussainbadshah)\
**Post date:** [December 6, 2023, 8:48am UTC](https://community.hivemq.com/t/hivemq-mqtt-5-client-not-connecting-to-mqtt-3-broker/2537/3 "2023-12-06T08:48:48Z")

</div>

@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?

---

<div class="post-metadata">

**Author:** ![michael\_w](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.hivemq.com/michael_w/32/200_2.png) [@michael\_w](https://community.hivemq.com/u/michael_w)\
**Post date:** [December 6, 2023, 6:06pm UTC](https://community.hivemq.com/t/hivemq-mqtt-5-client-not-connecting-to-mqtt-3-broker/2537/4 "2023-12-06T18:06:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hussainbadshah](https://avatars.discourse-cdn.com/v4/letter/h/a698b9/32.png) [@hussainbadshah](https://community.hivemq.com/u/hussainbadshah)\
**Post date:** [December 7, 2023, 5:14am UTC](https://community.hivemq.com/t/hivemq-mqtt-5-client-not-connecting-to-mqtt-3-broker/2537/5 "2023-12-07T05:14:13Z")

</div>

Hi @michael_w if you check the following website: [Implementing MQTT in Java](https://www.hivemq.com/blog/implementing-mqtt-in-java/#:~:text=Using%20the%20HiveMQ%20MQTT%20Client%20Library%20for%20Java&text=This%20library%20is%20a%20popular,API%20flavours%20and%20backpressure%20support).

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.

---

<div class="post-metadata">

**Author:** ![sauroter](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.hivemq.com/sauroter/32/18_2.png) [@sauroter](https://community.hivemq.com/u/sauroter)\
**Post date:** [December 7, 2023, 6:05am UTC](https://community.hivemq.com/t/hivemq-mqtt-5-client-not-connecting-to-mqtt-3-broker/2537/6 "2023-12-07T06:05:34Z")

</div>

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](https://github.com/hivemq/hivemq-mqtt-client/blob/master/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](https://hivemq.github.io/hivemq-mqtt-client/docs/client-configuration/):

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

```

I hope this helps

All the best  
Georg

---

<div class="post-metadata">

**Author:** ![hussainbadshah](https://avatars.discourse-cdn.com/v4/letter/h/a698b9/32.png) [@hussainbadshah](https://community.hivemq.com/u/hussainbadshah)\
**Post date:** [December 7, 2023, 7:12am UTC](https://community.hivemq.com/t/hivemq-mqtt-5-client-not-connecting-to-mqtt-3-broker/2537/7 "2023-12-07T07:12:17Z")

</div>

Thank you for all the information.

Warm Regards  
Hussain
