'queue'
This commit is contained in:
1 parent
8c98346546
commit
7073e9b4ba
2 files changed
+14
-6
No files matched your search
+2
-2
@@ -26,7 +26,7 @@ type Broker struct {
|
|||||||
remotes sync.Map
|
remotes sync.Map
|
||||||
sl *Sublist
|
sl *Sublist
|
||||||
rl *RetainList
|
rl *RetainList
|
||||||
queues map[string]Queue
|
queues map[string]*Queue
|
||||||
}
|
}
|
||||||
type Queue struct {
|
type Queue struct {
|
||||||
count int
|
count int
|
||||||
@@ -39,7 +39,7 @@ func NewBroker(config *Config) (*Broker, error) {
|
|||||||
config: config,
|
config: config,
|
||||||
sl: NewSublist(),
|
sl: NewSublist(),
|
||||||
rl: NewRetainList(),
|
rl: NewRetainList(),
|
||||||
queues: make(map[string]Queue),
|
queues: make(map[string]*Queue),
|
||||||
}
|
}
|
||||||
if b.config.TlsPort != "" {
|
if b.config.TlsPort != "" {
|
||||||
tlsconfig, err := NewTLSConfig(b.config.TlsInfo)
|
tlsconfig, err := NewTLSConfig(b.config.TlsInfo)
|
||||||
|
|||||||
+12
-4
@@ -221,21 +221,29 @@ func (c *client) ProcessPublishMessage(packet *packets.PublishPacket) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
idx, exist := b.queues[topic]
|
subinfo, exist := b.queues[topic]
|
||||||
|
qnum := 0
|
||||||
|
var qsub *subscription
|
||||||
if exist {
|
if exist {
|
||||||
|
idx := subinfo.index
|
||||||
}
|
|
||||||
for _, sub := range r.qsubs {
|
for _, sub := range r.qsubs {
|
||||||
if sub.client.typ == ROUTER {
|
if sub.client.typ == ROUTER {
|
||||||
if typ == ROUTER {
|
if typ == ROUTER {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if idx <= qnum {
|
||||||
|
qsub = sub
|
||||||
|
break
|
||||||
|
}
|
||||||
if sub.client.typ == CLIENT {
|
if sub.client.typ == CLIENT {
|
||||||
qnum = qnum + 1
|
qnum = qnum + 1
|
||||||
} else {
|
} else {
|
||||||
qnum = qnum + sub.client.rsubs[topic].num
|
qnum = qnum + sub.client.rsubs[topic].num
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
subinfo.index = (idx + 1) % subinfo.count
|
||||||
}
|
}
|
||||||
|
|
||||||
if qsub != nil {
|
if qsub != nil {
|
||||||
@@ -273,7 +281,7 @@ func (c *client) ProcessSubscribe(packet *packets.SubscribePacket) {
|
|||||||
if len(t) > 7 {
|
if len(t) > 7 {
|
||||||
t = t[7:]
|
t = t[7:]
|
||||||
if _, exists := b.queues[topic]; !exists {
|
if _, exists := b.queues[topic]; !exists {
|
||||||
b.queues[topic] = Queue{
|
b.queues[topic] = &Queue{
|
||||||
count: 0,
|
count: 0,
|
||||||
index: 0,
|
index: 0,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user