Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support setting extended client options #889

Draft
wants to merge 5 commits into
base: dev
Choose a base branch
from
Draft
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
10 changes: 9 additions & 1 deletion platforms/mqtt/mqtt_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Adaptor struct {
cleanSession bool
client paho.Client
qos int
optionsFn func(*paho.ClientOptions)
}

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

// SetOptionsFn sets the MQTT client extended options
func (a *Adaptor) SetOptionsFn(fn func(*paho.ClientOptions)) { a.optionsFn = fn }

// Connect returns true if connection to mqtt is established
func (a *Adaptor) Connect() error {
a.client = paho.NewClient(a.createClientOptions())
opts := a.createClientOptions()
if a.optionsFn != nil {
a.optionsFn(opts)
}
a.client = paho.NewClient(opts)
if token := a.client.Connect(); token.Wait() && token.Error() != nil {
return token.Error()
}
Expand Down