Support Will

This commit is contained in:
Nicolas Duhamel 2022-12-28 09:45:30 +01:00
parent 0c64ac1523
commit ba2acc3200

20
mqtt.go
View File

@ -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)
}