eclipse-paho / eclipse-paho/paho.mqtt.java

v3 subscribers can receive offline messages, but v5 cannot

Open
#1,048 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
2.3k
Forks
919
PR merge metrics
No merged PRs in 30d

Description

1: Start the subscribers implemented by v3 and v5 respectively

```

org.eclipse.paho
org.eclipse.paho.client.mqttv3
1.2.0


org.eclipse.paho
org.eclipse.paho.mqttv5.client
1.2.5

```
v5

```

import org.eclipse.paho.mqttv5.*
public class MqttSubscriberv5 {
public static void main(String[] args) {
String topic = "/test/topic0716";
String broker = "*****";
String clientId = "JavaSubSample0716v5";
try {
MqttConnectionOptions options = new MqttConnectionOptions();
options.setCleanStart(false);
options.setSessionExpiryInterval(0L);
options.setSocketFactory(SSLSocketBuilder.getSSLSocketFactory());
MqttClient mqttClient = new MqttClient(broker, clientId);
mqttClient.setCallback(new MqttCallback() {
@Override
public void disconnected(MqttDisconnectResponse disconnectResponse) {
System.out.println("==========disconnected");
}
@Override
public void mqttErrorOccurred(MqttException exception) {
}
@Override
public void messageArrived(String topic, MqttMessage message) throws Exception {
System.out.println(topic + ": --------" + message);
}
@Override
public void deliveryComplete(IMqttToken token) {
}
@Override
public void connectComplete(boolean reconnect, String serverURI) {
}
@Override
public void authPacketArrived(int reasonCode, MqttProperties properties) {
}
});
mqttClient.connect(options);
mqttClient.subscribe(topic, 1);
} catch (MqttException e) {
throw new RuntimeException(e);
}
}
}
```
v3
```
import org.eclipse.paho.client.mqttv3.*;
import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence;
public class SubscribeSamplev3 {
public static void main(String[] args) {
String topic = "/test/topic0716";
String broker = "********";
String clientId = "JavaSubSample0716v3";

try {
MqttClient client = new MqttClient(broker, clientId);
MqttConnectOptions options = new MqttConnectOptions();
options.setCleanSession(false);
options.setSocketFactory(SSLSocketBuilder.getSSLSocketFactory());
client.setCallback(new MqttCallback() {

public void connectionLost(Throwable cause) {
System.out.println("connectionLost subscribe: " + cause.getMessage());
}

public void messageArrived(String topic, MqttMessage message) {
System.out.println("topic subscribe: " + topic);
System.out.println("Qos subscribe: " + message.getQos());
System.out.println("message content subscribe: " + new String(message.getPayload()));
}

public void deliveryComplete(IMqttDeliveryToken token) {
System.out.println("deliveryComplete subscribe---------" + token.isComplete());
}

});
client.connect(options);
client.subscribe(topic, 1);
} catch (Exception e) {
e.printStackTrace();
}
}
}
```
2: Push a message.At this time, both v3 and v5 can receive the "hello world" message.
```
mosquitto_pub -h test.ota.autox.clu -p 38883 \
--cafile Root_CA.crt \
--cert client.crt \
--key client.key \
-t '*******' \
-q 1 \
-i testpub0716 \
-m "Hello World"
```

3: Stop the subscribers implemented by v3 and v5. And push a message again.
```
mosquitto_pub -h test.ota.autox.clu -p 38883 \
--cafile Root_CA.crt \
--cert client.crt \
--key client.key \
-t '*******' \
-q 1 \
-i testpub0716 \
-m "Hello World My God "
```

4: Start the subscribers implemented by v3 and v5 again. v3 can receive "Hello World My God " message sent in step 3, but v5 cannot

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the v3 and v5 subscribers using the dependency versions and MQTT commands in the report. Compare their connection, session, and subscription behavior across the stop, publish, and restart steps. Done means the v5 subscriber receives the QoS 1 message published while it was stopped, matching v3.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.