Closed Blafasel3 closed 1 year ago
Hi @Blafasel3,
I've also seen this hang prior to the connect call a few times and I'll look to investigate this soon.
In the meantime, there is another code pattern you can use to work around this issue. It involves setting the message handler prior to the connect call as follows:
client.toAsync().publishes(MqttGlobalPublishFilter.SUBSCRIBED, mqtt5Publish -> {
System.out.println("received message: " + mqtt5Publish);
});
So the full code flow would be:
Mqtt5AsyncClient client = Mqtt5Client.builder().identifier("mqttConsumer")
.serverHost(host)
.serverPort(port)
// <snip>
.buildAsync();
client.toAsync().publishes(MqttGlobalPublishFilter.SUBSCRIBED, mqtt5Publish -> {
System.out.println("received message: " + mqtt5Publish);
});
final Mqtt5ConnAck connAck = client.toBlocking().connectWith()
.cleanStart(false) // resume a previous session
.sessionExpiryInterval(300) // keep session state for 300s
.send();
I hope this helps - please let me know latest status.
I believe my previous post should resolve the subscribe issue so I'm going to close out this issue. If anything remains, please feel free to re-open or file another issue. We'd be very happy to help out.
Expected behavior
Subscribing should be possible before connecting the client - as described in https://github.com/hivemq/hivemq-mqtt-client/issues/521.
Actual behavior
Subscribing before connecting blocks forever.
To Reproduce
Steps
cleanSession = false
because we are not allowed to loose those messagessessionExpiryInterval
is set to 6000MqttIncomingPublishService
acknowledges the message even if there is no publish flow registered:Reproducer code
Subscribing to messages before the connect does not work . The
Single.timer
is there to enforce the race condition we observed.Same behavior using
subscribeSingleFuture
(subscriptions
is just a config POJO we use to configure the topics.):Details