eclipse / paho.mqtt.java

Eclipse Paho Java MQTT client library. Paho is an Eclipse IoT project.
https://eclipse.org/paho
Other
2.12k stars 883 forks source link

UserProperties with the same name are not possible #938

Closed YannickWeber closed 2 years ago

YannickWeber commented 2 years ago

Expected behaviour

Publishing user properties with the same name is possible. E.g.

        UserProperty header1 = new UserProperty("app-id", "0000000000000000000");
        UserProperty header2 = new UserProperty("app-id", "0000000000000000001");
        UserProperty header3 = new UserProperty("trace-id", "0000000000000000002");

Actual behaviour

Only one user property with the duplicate name is present, when receiving the PUBLISH:

$ mqtt sub -t # -J
{
  "topic": "my-topic",
  "payload": "test",
  "qos": "AT_LEAST_ONCE",
  "receivedAt": "2022-06-02 17:29:36",
  "retain": false,
  "userProperties": {
    "app-id": "0000000000000000001",
    "trace-id": "0000000000000000002"
  }
}

Reproducer

public class Publisher {

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

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

        List<UserProperty> userProperties = new ArrayList<>();
        UserProperty header1 = new UserProperty("app-id", "0000000000000000000");
        UserProperty header2 = new UserProperty("app-id", "0000000000000000001");
        UserProperty header3 = new UserProperty("trace-id", "0000000000000000002");
        userProperties.add(header1);
        userProperties.add(header2);
        userProperties.add(header3);
        proper.setUserProperties(userProperties);

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

        client.publish("my-topic", message);
    }
}
YannickWeber commented 2 years ago

I found out that this is an issue with my command line client.