mirror of
https://github.com/pgsty/minio.git
synced 2026-08-10 00:03:29 +03:00
Persist offline mqtt events in the queueDir and replay (#7037)
This commit is contained in:
committed by
Harshavardhana
parent
8757c963ba
commit
6571641735
+30
-7
@@ -15,7 +15,10 @@
|
||||
package mqtt
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
|
||||
"github.com/eclipse/paho.mqtt.golang/packets"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Message defines the externals that a message implementation must support
|
||||
@@ -28,6 +31,7 @@ type Message interface {
|
||||
Topic() string
|
||||
MessageID() uint16
|
||||
Payload() []byte
|
||||
Ack()
|
||||
}
|
||||
|
||||
type message struct {
|
||||
@@ -37,6 +41,8 @@ type message struct {
|
||||
topic string
|
||||
messageID uint16
|
||||
payload []byte
|
||||
once sync.Once
|
||||
ack func()
|
||||
}
|
||||
|
||||
func (m *message) Duplicate() bool {
|
||||
@@ -63,7 +69,11 @@ func (m *message) Payload() []byte {
|
||||
return m.payload
|
||||
}
|
||||
|
||||
func messageFromPublish(p *packets.PublishPacket) Message {
|
||||
func (m *message) Ack() {
|
||||
m.once.Do(m.ack)
|
||||
}
|
||||
|
||||
func messageFromPublish(p *packets.PublishPacket, ack func()) Message {
|
||||
return &message{
|
||||
duplicate: p.Dup,
|
||||
qos: p.Qos,
|
||||
@@ -71,10 +81,11 @@ func messageFromPublish(p *packets.PublishPacket) Message {
|
||||
topic: p.TopicName,
|
||||
messageID: p.MessageID,
|
||||
payload: p.Payload,
|
||||
ack: ack,
|
||||
}
|
||||
}
|
||||
|
||||
func newConnectMsgFromOptions(options *ClientOptions) *packets.ConnectPacket {
|
||||
func newConnectMsgFromOptions(options *ClientOptions, broker *url.URL) *packets.ConnectPacket {
|
||||
m := packets.NewControlPacket(packets.Connect).(*packets.ConnectPacket)
|
||||
|
||||
m.CleanSession = options.CleanSession
|
||||
@@ -88,17 +99,29 @@ func newConnectMsgFromOptions(options *ClientOptions) *packets.ConnectPacket {
|
||||
m.WillMessage = options.WillPayload
|
||||
}
|
||||
|
||||
if options.Username != "" {
|
||||
username := options.Username
|
||||
password := options.Password
|
||||
if broker.User != nil {
|
||||
username = broker.User.Username()
|
||||
if pwd, ok := broker.User.Password(); ok {
|
||||
password = pwd
|
||||
}
|
||||
}
|
||||
if options.CredentialsProvider != nil {
|
||||
username, password = options.CredentialsProvider()
|
||||
}
|
||||
|
||||
if username != "" {
|
||||
m.UsernameFlag = true
|
||||
m.Username = options.Username
|
||||
m.Username = username
|
||||
//mustn't have password without user as well
|
||||
if options.Password != "" {
|
||||
if password != "" {
|
||||
m.PasswordFlag = true
|
||||
m.Password = []byte(options.Password)
|
||||
m.Password = []byte(password)
|
||||
}
|
||||
}
|
||||
|
||||
m.Keepalive = uint16(options.KeepAlive.Seconds())
|
||||
m.Keepalive = uint16(options.KeepAlive)
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user