-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.go
More file actions
42 lines (39 loc) · 869 Bytes
/
queue.go
File metadata and controls
42 lines (39 loc) · 869 Bytes
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
33
34
35
36
37
38
39
40
41
42
// @description package main
package main
import (
"container/list"
"github.com/go-redis/redis"
"log"
"net"
"sync"
"time"
)
func PublishMessage(rdb *redis.Client, record Record) {
res, err := rdb.Publish("queueconfcarrier", ToJsonString(record)).Result()
if err != nil {
log.Println(err, res)
time.Sleep(time.Duration(2) * time.Second)
PublishMessage(rdb, record)
}
}
func SubscribeMessage(rdb *redis.Client, m *sync.Map) {
pubSub := rdb.Subscribe("queueconfcarrier")
ch := pubSub.Channel()
for msg := range ch {
record := ToInterface(msg.Payload)
val, _ := m.Load(record.Namespace)
if val == nil {
} else {
queue := val.(*list.List)
for i := queue.Front(); i != nil; i = i.Next() {
c := i.Value.(*net.TCPConn)
if c != nil {
Response{
Code: SUCCESS,
Data: record,
}.Return(c, NOTIFY)
}
}
}
}
}