No connect after disconnect

I have the following listeners:

var client = Mqtt3Client.builder().serverHost(host).serverPort(1883).identifier(clientId).addConnectedListener(
 				context -> System.out.println("connected  " + LocalTime.now() + " host: " + context.getClientConfig().getServerHost()
 					+ " client: " + context.getClientConfig().getClientIdentifier())).addDisconnectedListener(context -> {
 				System.out.println("disconnected - " + " cause: " + context.getCause() + " source:" + context.getSource() + " " + LocalTime.now());
 				 context.getReconnector()
          .reconnect(context.getSource() != MqttDisconnectSource.USER)
          .delay(2 * context.getReconnector().getAttempts(), TimeUnit.SECONDS);
 			}).buildBlocking();
 			client.connectWith().simpleAuth().username(user).password(UTF_8.encode(passwd)).applySimpleAuth().send();

Occasionaly, I get this:

Sep 11 19:50:32 cama java[20789]: disconnected -  cause: com.hivemq.client.mqtt.exceptions.ConnectionClosedException: Server closed connection without DISCONNECT. source:SERVER 19:50:32.254664938
Sep 11 19:50:32 cama java[20789]: disconnected -  cause: com.hivemq.client.mqtt.exceptions.ConnectionClosedException: Server closed connection without DISCONNECT. source:SERVER 19:50:32.555904961
Sep 11 19:50:34 cama java[20789]: disconnected -  cause: com.hivemq.client.mqtt.exceptions.ConnectionClosedException: Server closed connection without DISCONNECT. source:SERVER 19:50:34.609964
Sep 11 19:50:38 cama java[20789]: disconnected -  cause: com.hivemq.client.mqtt.exceptions.ConnectionClosedException: Server closed connection without DISCONNECT. source:SERVER 19:50:38.658020411
....

However, there seems to be no reconnect attempt ?

Kind regards
Peter

@pvittali , your code works correctly for me, both “connected” and “disconnected” messages are logged:

> Task :hivemq-mqtt-client-examples:ReconnectStrategy.main()
connected  16:28:02.560254 host: localhost client: Optional[javaExample]
disconnected -  cause: com.hivemq.client.mqtt.mqtt5.exceptions.Mqtt5DisconnectException: Server sent DISCONNECT. source:SERVER 16:28:46.023927
connected  16:28:46.072637 host: localhost client: Optional[javaExample]
disconnected -  cause: com.hivemq.client.mqtt.mqtt5.exceptions.Mqtt5DisconnectException: Server sent DISCONNECT. source:SERVER 16:29:45.974866
connected  16:29:46.034585 host: localhost client: Optional[javaExample]

I suggest you first to to disable authentication in your HiveMQ and test your Java code without username and password.
While testing, watch the event.log for connection and disconnection events (where the Client ID == clientId from your Java code).

I hope this helps
Dasha from HiveMQ team

HI Daria
Interestingly, you get the connected - disconnected pair, by I really don’t, as you can see, only the disconnect messages appear in my log …

I noticed that when I restart the application, thus recreating the Mqtt3BlockingClient is get a connection immediately. So somehow the reconnect listeners do not really perform a “fresh” connect ?