I am using the HiveMQ MQTT client in Spring to receive MQTT messages.
My client configuration looks like this
public Mqtt3AsyncClient mqtt3Client() {
var mqtt3Client = Mqtt3Client.builder()
.serverHost("my.host")
.sslWithDefaultConfig()
.serverPort(0000)
.automaticReconnectWithDefaultConfig()
.buildBlocking();
mqtt3Client.connect();
return mqtt3Client.toAsync();
}
After the client is available, another Spring Bean is initialized using the client. It subscribes a topic:
@PostConstruct
public void subscribeTopic() {
mqtt3AsyncClient.subscribeWith()
.topicFilter("topicfilter")
.qos(MqttQos.AT_LEAST_ONCE)
.callback(message -> {
/*Handle message*/
})
.send()
.whenComplete((mqtt3SubAck, throwable) -> {
if (throwable != null) {
/*Logging*/
} else {
/*Logging*/
}
});
}
I saw multiple times that no more messages were delivered to my application while I was still able to use the client connection to send messages (thus it was connected at that time).
I could not find any documentation on how the HiveMQ MQTT client handles the configured automaticReconnectWithDefaultConfig()
. Can anyone point out, whether my subscription created in subscribeTopic()
is resubscribed?
I also found the method addSubscription()
that may replace the .topicFilter(..).qos(...)
part. I also could no find any information whether this makes the subscription more resilient to connection losses.
I'd appreciate any kind of information on that topic.
Thanks.