Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions plugins/common/mqtt/mqtt_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,15 @@ func NewMQTTv311Client(cfg *MqttConfig) (*mqttv311Client, error) {
return nil, err
}
for _, server := range servers {
if tlsCfg != nil {
server.Scheme = "tls"
switch server.Scheme {
case "ws":
// Keep ws:// as-is
case "wss":
// Keep wss:// as-is
default:
if tlsCfg != nil {
server.Scheme = "tls"
}
}
broker := server.String()
opts.AddBroker(broker)
Expand Down
9 changes: 7 additions & 2 deletions plugins/common/mqtt/mqtt_v5.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,13 @@ func NewMQTTv5Client(cfg *MqttConfig) (*mqttv5Client, error) {

brokers := make([]*url.URL, 0, len(servers))
for _, server := range servers {
if tlsCfg != nil {
server.Scheme = "tls"
switch server.Scheme {
case "ws", "wss":
// Keep websocket schemes as-is
default:
if tlsCfg != nil {
server.Scheme = "tls"
}
}
brokers = append(brokers, server)
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/outputs/mqtt/sample.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
## The list of brokers should only include the hostname or IP address and the
## port to the broker. This should follow the format `[{scheme}://]{host}:{port}`. For
## example, `localhost:1883` or `mqtt://localhost:1883`.
## Scheme can be any of the following: tcp://, mqtt://, tls://, mqtts://
## Scheme can be any of the following: tcp://, mqtt://, tls://, mqtts://, ws://, wss://
## non-TLS and TLS servers can not be mix-and-matched.
servers = ["localhost:1883", ] # or ["mqtts://tls.example.com:1883"]
servers = ["localhost:1883", ] # or ["mqtts://tls.example.com:1883"] or ["wss://broker.example.com:443"]

## Protocol can be `3.1.1` or `5`. Default is `3.1.1`
# protocol = "3.1.1"
Expand Down
Loading