HiveMQ

Handling messages issue after some time

Hi,

I started using HiveMQ MQTT Client aprox 2-3months ago and until now I got twice same error but not sure if I made some mistake on my side or not.

I have create and connect client by:

Mqtt5AsyncClient client = MqttClient.builder()
        .useMqttVersion5()
        .identifier(clientId != null ? clientId : UUID.randomUUID().toString())
        .serverHost(host)
        .serverPort(port)
        .automaticReconnect()
	        .initialDelay(RECONNECT_MIN_DELAY, TimeUnit.SECONDS)
	        .maxDelay(RECONNECT_MAX_DELAY, TimeUnit.SECONDS)
	        .applyAutomaticReconnect()
        .addDisconnectedListener(new MqttClientDisconnectedListener() {
			@Override
			public void onDisconnected( MqttClientDisconnectedContext context) {
				LOGGER.warn("Disconnected");
			}
		})
        .addConnectedListener(new MqttClientConnectedListener() {
			@Override
			public void onConnected(MqttClientConnectedContext context) {
				LOGGER.info("Connected");
			}
		})
        .buildAsync();

client.connectWith().send().whenComplete(new BiConsumer<Mqtt5ConnAck, Throwable>() {
	@Override
	public void accept(Mqtt5ConnAck t, Throwable u) {
		if(u != null) {
			LOGGER.error("Error during connection to server: " + u.getMessage(), u);
		} else {
			LOGGER.info("Connected to {} and port {}", host, port);
		}
	}
});

I have subscribed 5 topics:

client.subscribeWith()
		.topicFilter(topic)
		.qos(MqttQos.fromCode(qos.getQos()))
		.callback(
					new Consumer<Mqtt5Publish>() {
						
						@Override
						public void accept(Mqtt5Publish protoMessage) {
							callback.onMessage(protoMessage);
						}
					}
				)
		.send();

I got this error which was appeared on most of received message:

2021-06-09 09:06:34.323 [ERROR] --- [com.hivemq.client.mqtt-1-1] c.h.c.i.m.h.p.i.MqttIncomingQosHandler : QoS 1 PUBLISH (MqttStatefulPublish{stateless=MqttPublish{topic=my_topic, payload=43byte, qos=AT_LEAST_ONCE, retain=false}, packetIdentifier=1, dup=false, topicAlias=0, subscriptionIdentifiers=[3]}) must not be resent (MqttStatefulPublish{stateless=MqttPublish{topic=my_topic, payload=43byte, qos=AT_LEAST_ONCE, retain=false}, packetIdentifier=1, dup=true, topicAlias=0, subscriptionIdentifiers=[3]}) during the same connection
com.hivemq.client.mqtt.mqtt5.exceptions.Mqtt5DisconnectException: QoS 1 PUBLISH must not be resent during the same connection
2021-06-09 09:06:34.324 [WARN] --- [com.hivemq.client.mqtt-1-1] c.u.p.core.mqtt.client.HiveMQClient : Disconnected
2021-06-09 09:06:38.897 [INFO] --- [com.hivemq.client.mqtt-1-1] c.u.p.core.mqtt.client.HiveMQClient : Connected

First time what happend to me I only restarted app and error disappered because. (I did not have time to solve it but I stored the logs)
After 5 week error appered again. Four of my five topics on message first handled message after that I got this error and client reconnected. Messages of one topic was not even handled only error was logged. All subscribtions use same callback class (each has own instance), callback’s onMessage method contains topic parsing, store data to database, wrap message and send to Kafka.

First one or two days what data were not comming to database from that one topic I did not see any error in log.

Does anyone has idea where is the root of this error and what caused it and how to repaire it?

Thanks,
Roman