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

MqttTopic.publish() drops UserProperties

Open
#937 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

Please fill out the form below before submitting, thank you!

- [x] Bug exists Release Version 1.2.5 ( Master Branch)
- [ ] Bug exists in MQTTv3 Client on Snapshot Version 1.2.6-SNAPSHOT (Develop Branch)
- [x] Bug exists in MQTTv5 Client on Snapshot Version 1.2.6-SNAPSHOT (Develop Branch)

# Expected behaviour
MqttTopic.publish(...) correctly sends the user properties

# Actual behaviour
MqttTopic.publish(...) does not send user properties

# Reproducer
```
public class Publisher {

public static void main(final String[] args) throws MqttException {
MqttClient client = new MqttClient("tcp://localhost:1883", "my-client");
client.connect();

MqttTopic topic = client.getTopic("prop/topic");

MqttMessage message = new MqttMessage("test".getBytes(StandardCharsets.UTF_8));
MqttProperties proper = new MqttProperties();

List userProperties = new ArrayList<>();
UserProperty header1 = new UserProperty("name1", "value1");
UserProperty header2 = new UserProperty("name1", "value2");
UserProperty header3 = new UserProperty("name2", "value3");
userProperties.add(header1);
userProperties.add(header2);
userProperties.add(header3);
proper.setUserProperties(userProperties);

message.setProperties(proper);
message.setQos(1);

topic.publish(message);
}
}
```

# Problem
I think this problem happens because the method MqttTopic.publish() creates a new `MqttProperties` instead of taking the one provided by `message`:
```
public MqttToken publish(MqttMessage message) throws MqttException, MqttPersistenceException {
MqttToken token = new MqttToken(comms.getClient().getClientId());
token.internalTok.setDeliveryToken(true);
token.setMessage(message);
comms.sendNoWait(createPublish(message, new MqttProperties()), token);
token.internalTok.waitUntilSent();
return token;
}
```

Contributor guide

Open the contributing guide

Research direction

Start with MqttTopic.publish() and its createPublish(...) call, using the supplied Java reproducer to trace how message properties are handled. Confirm that the UserProperties configured on MqttMessage are sent by MQTTv5 publishing, and verify the behavior with an appropriate client or test.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
networking
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.