Support Will
This commit is contained in:
parent
0c64ac1523
commit
ba2acc3200
20
mqtt.go
20
mqtt.go
@ -69,22 +69,9 @@ type Config struct {
|
||||
Retained bool
|
||||
KeepAlive time.Duration
|
||||
MsgChanDept uint
|
||||
WillMessage PubMessage
|
||||
}
|
||||
|
||||
// return &Config{
|
||||
// Host: host,
|
||||
// Port: port,
|
||||
// Username: username,
|
||||
// Password: password,
|
||||
// ClientID: clientId,
|
||||
// CleanSession: true,
|
||||
// AutoReconnect: true,
|
||||
// Retained: false,
|
||||
// KeepAlive: 15 * time.Second,
|
||||
// MsgChanDept: 100,
|
||||
// }
|
||||
// }
|
||||
|
||||
type Client struct {
|
||||
Config Config
|
||||
pahoClient paho.Client
|
||||
@ -103,6 +90,11 @@ func New(conf Config) *Client {
|
||||
opts.SetAutoReconnect(conf.AutoReconnect)
|
||||
opts.SetKeepAlive(conf.KeepAlive)
|
||||
opts.SetMessageChannelDepth(conf.MsgChanDept)
|
||||
|
||||
if conf.WillMessage != nil {
|
||||
m := conf.WillMessage
|
||||
opts.SetBinaryWill(m.Topic(), m.Payload(), m.Qos(), m.Retained())
|
||||
}
|
||||
if conf.AutoReconnect {
|
||||
opts.SetResumeSubs(true)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user