Skip to content

Commit f352e12

Browse files
author
shegaoyuan@aliyun.com
committed
fixed bug 863, support sets the MQTT client extended options, usage: mqttAdaptor := mqtt.NewAdaptorWithAuth(...); mqttAdaptor.SetOptionsFn(func(opts *paho.ClientOptions) {opts.WillPayload = []byte("goodbye")
1 parent ed0c79a commit f352e12

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

platforms/mqtt/mqtt_adaptor.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type Adaptor struct {
3232
cleanSession bool
3333
client paho.Client
3434
qos int
35+
optionsFn func(*paho.ClientOptions)
3536
}
3637

3738
// NewAdaptor creates a new mqtt adaptor with specified host and client id
@@ -109,9 +110,16 @@ func (a *Adaptor) ClientKey() string { return a.clientKey }
109110
// SetClientKey sets the MQTT client SSL key file
110111
func (a *Adaptor) SetClientKey(val string) { a.clientKey = val }
111112

113+
// SetOptionsFn sets the MQTT client extended options
114+
func (a *Adaptor) SetOptionsFn(fn func(*paho.ClientOptions)) { a.optionsFn = fn }
115+
112116
// Connect returns true if connection to mqtt is established
113117
func (a *Adaptor) Connect() error {
114-
a.client = paho.NewClient(a.createClientOptions())
118+
opts := a.createClientOptions()
119+
if a.optionsFn != nil {
120+
a.optionsFn(opts)
121+
}
122+
a.client = paho.NewClient(opts)
115123
if token := a.client.Connect(); token.Wait() && token.Error() != nil {
116124
return token.Error()
117125
}

0 commit comments

Comments
 (0)