Adding small coalesce on scheme to ensure backward compatibility in both the pubsub and binding mqtt components

This commit is contained in:
Phil Kedy 2021-04-06 17:30:33 -04:00
parent 55b6657d1c
commit 810ec429a7
2 changed files with 18 additions and 2 deletions

View File

@ -293,7 +293,15 @@ func (m *MQTT) createClientOptions(uri *url.URL, clientID string) *mqtt.ClientOp
opts := mqtt.NewClientOptions()
opts.SetClientID(clientID)
opts.SetCleanSession(m.metadata.cleanSession)
opts.AddBroker(uri.Scheme + "://" + uri.Host)
// URL scheme backward compatibility
scheme := uri.Scheme
switch scheme {
case "mqtt":
scheme = "tcp"
case "mqtts":
scheme = "ssl"
}
opts.AddBroker(scheme + "://" + uri.Host)
opts.SetUsername(uri.User.Username())
password, _ := uri.User.Password()
opts.SetPassword(password)

View File

@ -286,7 +286,15 @@ func (m *mqttPubSub) createClientOptions(uri *url.URL, clientID string) *mqtt.Cl
opts := mqtt.NewClientOptions()
opts.SetClientID(clientID)
opts.SetCleanSession(m.metadata.cleanSession)
opts.AddBroker(uri.Scheme + "://" + uri.Host)
// URL scheme backward compatibility
scheme := uri.Scheme
switch scheme {
case "mqtt":
scheme = "tcp"
case "mqtts":
scheme = "ssl"
}
opts.AddBroker(scheme + "://" + uri.Host)
opts.SetUsername(uri.User.Username())
password, _ := uri.User.Password()
opts.SetPassword(password)