hivemq / hivemq-mqtt-client

HiveMQ MQTT Client is an MQTT 5.0 and MQTT 3.1.1 compatible and feature-rich high-performance Java client library with different API flavours and backpressure support
https://hivemq.github.io/hivemq-mqtt-client/
Apache License 2.0
847 stars 158 forks source link

Server closed connection without DISCONNECT. #506

Closed liulongblog closed 2 years ago

liulongblog commented 2 years ago

DisconnectedListener log : 2021-09-15 13:53:12.739 INFO 12892 --- [client.mqtt-4-6] com.....mqtt.MqttClient : [MqttClient] disconnected by SERVER, cause {}

com.hivemq.client.mqtt.exceptions.ConnectionClosedException: Server closed connection without DISCONNECT.

client config as follow: Mqtt3ClientBuilder mqtt3ClientBuilder = com.hivemq.client.mqtt.MqttClient.builder() .useMqttVersion3() .identifier(clientId) .serverHost(StringUtils.substringBetween(properties.getUrl(), "//", ":")) .serverPort(Integer.parseInt(StringUtils.substringAfterLast(properties.getUrl(), ":"))) .addConnectedListener(mqttClientConnectedListener) .addDisconnectedListener(mqttClientDisconnectedListener)

            .automaticReconnect(MqttClientAutoReconnect.builder().initialDelay(5, TimeUnit.SECONDS)
                    .maxDelay(2, TimeUnit.MINUTES).build());

    if (properties.getAuthType() == AuthTypeEnum.USERNAME) {
        mqtt3ClientBuilder = mqtt3ClientBuilder.simpleAuth().username(properties.getUsername())
                .password(properties.getPassword().getBytes(
                        StandardCharsets.UTF_8))
                .applySimpleAuth();
    } else if (properties.getAuthType() == AuthTypeEnum.X509) {

    }
    this.client = mqtt3ClientBuilder.buildAsync();

can i consume that is a problem of server?

liulongblog commented 2 years ago

solved

dinhthaidaica commented 1 year ago

@liulongblog Could you explain why did it happen and how to fix? I ran into the same issue and couldn't figure it out.

dinhthaidaica commented 1 year ago

It seems to be a Mqtt5Client problem. It just disappeared when I switched to Mqtt3Client. So my best guess is incompatible between Client and Broker.

liulongblog commented 1 year ago

It seems to be a Mqtt5Client problem. It just disappeared when I switched to Mqtt3Client. So my best guess is incompatible between Client and Broker.

my problem :client connect without synchronized, the same clientid was kicked by server