eclipse-archived / smarthome

Eclipse SmartHome™ project
https://www.eclipse.org/smarthome/
Eclipse Public License 2.0
862 stars 783 forks source link

MQTT: Add protocol selection to MqttBrokerConnection #5370

Closed davidgraeff closed 6 years ago

davidgraeff commented 6 years ago

Abstract

At the moment the MqttBrokerConnection class assumes that the API user wants a TCP (+SSL) connection. MQTT is also specified for Websockets nowadays though. There might be additional transport protocols specified for MQTTv5.

Usecase

For example to talk to the amazon IOT (AWS) cloud that speaks MQTT on websockets.

Regression

The old API just required an URI string like "tcp://1.1.1.1:1234", which defeats any means of type safety and required an extra portion of parsing, but was nicely extensible.

Suggestion

Add a second constructor for this probably not so often used feature of selecting another protocol. I have this in mind:

enum Protocol {
   TCP,
   WEBSOCKET
};

public MqttBrokerConnection(Protocol protocol, String host, @Nullable Integer port, boolean secure, @Nullable String clientId) {
}

public MqttBrokerConnection(String host, @Nullable Integer port, boolean secure, @Nullable String clientId) {
}

I would not introduce a Builder here, because all parameters are related to each other and basically resemble an URI and are easy to grasp.

htreu commented 6 years ago

Hi @davidgraeff, this looks okay to me. For the HTTP headers I suggest to opening a separate issue.