forked from VolantMQ/volantmq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
broker.go
32 lines (26 loc) · 879 Bytes
/
broker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package systree
import (
"github.com/troian/surgemq/message"
"github.com/troian/surgemq/types"
)
type broker struct {
version string
upTime *dynamicValueUpTime
currTime *dynamicValueCurrentTime
}
func newBroker(topicPrefix string, dynRetains, staticRetains *[]types.RetainObject) broker {
b := broker{
upTime: newDynamicValueUpTime(topicPrefix + "/uptime"),
currTime: newDynamicValueCurrentTime(topicPrefix + "/datetime"),
version: "1.0.0",
}
m, _ := message.NewMessage(message.ProtocolV311, message.PUBLISH)
msg, _ := m.(*message.PublishMessage)
msg.SetQoS(message.QoS0) // nolint: errcheck
msg.SetTopic(topicPrefix + "/version") // nolint: errcheck
msg.SetPayload([]byte(b.version))
*dynRetains = append(*dynRetains, b.upTime)
*dynRetains = append(*dynRetains, b.currTime)
*staticRetains = append(*staticRetains, msg)
return b
}