Open YannickWeber opened 2 years ago
Please fill out the form below before submitting, thank you!
MqttTopic.publish(...) correctly sends the user properties
MqttTopic.publish(...) does not send user properties
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<UserProperty> 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); } }
I think this problem happens because the method MqttTopic.publish() creates a new MqttProperties instead of taking the one provided by message:
MqttProperties
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; }
Please fill out the form below before submitting, thank you!
Expected behaviour
MqttTopic.publish(...) correctly sends the user properties
Actual behaviour
MqttTopic.publish(...) does not send user properties
Reproducer
Problem
I think this problem happens because the method MqttTopic.publish() creates a new
MqttProperties
instead of taking the one provided bymessage
: