Open andsel opened 5 months ago
I think I've found an issue that could be related to this:
@Test
public void test() throws Exception {
final Mqtt5BlockingClient publisher = com.hivemq.client.mqtt.MqttClient.builder()
.useMqttVersion5()
.identifier("publisher")
.serverHost("localhost")
.serverPort(1883)
.buildBlocking();
Mqtt5Connect connectRequest = Mqtt5Connect.builder()
.cleanStart(true)
.build();
assertEquals(Mqtt5ConnAckReasonCode.SUCCESS, publisher.connect(connectRequest).getReasonCode(), "publisher" + " connected");
//publish a retained message
publisher.publishWith()
.topic("metric/temperature/living")
.payload("18".getBytes(StandardCharsets.UTF_8))
.retain(true)
.qos(MqttQos.AT_LEAST_ONCE)
.send();
// receive retained only if new subscription
final Mqtt5BlockingClient subscriber = com.hivemq.client.mqtt.MqttClient.builder()
.useMqttVersion5()
.identifier("subscriber")
.serverHost("localhost")
.serverPort(1883)
.buildBlocking();
assertEquals(Mqtt5ConnAckReasonCode.SUCCESS, subscriber.connect().getReasonCode(), "subscriber" + " connected");
subscriber.subscribeWith()
.topicFilter("metric/temperature/living")
.qos(MqttQos.AT_LEAST_ONCE)
.retainHandling(Mqtt5RetainHandling.SEND_IF_SUBSCRIPTION_DOES_NOT_EXIST)
.send();
try (Mqtt5BlockingClient.Mqtt5Publishes publishes = subscriber.publishes(MqttGlobalPublishFilter.ALL)) {
Optional<Mqtt5Publish> publishMessage = publishes.receive(1, TimeUnit.SECONDS);
if (!publishMessage.isPresent()) {
fail("Expected to receive a publish message");
return;
}
Mqtt5Publish pub = publishMessage.get();
assertEquals("18", new String(pub.getPayloadAsBytes(), StandardCharsets.UTF_8));
}
}
π Bug Report
A publisher publish a retained message, after that a subscriber subscribe to the same topic and should receive the retained message despite at wire level the publish happens.
π¬ How To Reproduce
Steps to reproduce the behavior:
Run the next test code
Code sample
Environment
Where are you running/using this client? On embedded test
Hardware or Device? not important
What version of this client are you using? 1.3.3
JVM version? Adoptium 17
Operating System? MacOS
Which MQTT protocol version is being used? MQTT 5
Which MQTT broker (name and version)? Moquette 0.18-SNAPSHOT
Screenshots
π Expected behavior
Once a subscriber subscribe to a topic that matches a previously retained message, when the PUB message reaches the client, than that message should be pushed to the listener.
π Additional context
pcap that demonstrate that the publish reaches the client. pub_retained.pcapng.gz