-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathreload_signal.go
50 lines (42 loc) · 1.09 KB
/
reload_signal.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"encoding/json"
"github.com/Sirupsen/logrus"
"github.com/garyburd/redigo/redis"
"time"
)
const (
RedisPubSubChannel string = "tyk.cluster.notifications"
)
func StartPubSubLoop() {
CacheStore := RedisClusterStorageManager{}
CacheStore.Connect()
// On message, synchronise
for {
err := CacheStore.StartPubSubHandler(RedisPubSubChannel, HandleRedisReloadMsg)
if err != nil {
log.WithFields(logrus.Fields{
"prefix": "pub-sub",
"err": err,
}).Error("Connection to Redis failed, reconnect in 10s")
time.Sleep(10 * time.Second)
log.WithFields(logrus.Fields{
"prefix": "pub-sub",
}).Warning("Reconnecting")
CacheStore.Connect()
CacheStore.StartPubSubHandler(RedisPubSubChannel, HandleRedisReloadMsg)
}
}
}
func HandleRedisReloadMsg(message redis.Message) {
thisMessage := Notification{}
err := json.Unmarshal(message.Data, &thisMessage)
if err != nil {
log.Error("Unmarshalling message body failed, malformed: ", err)
return
}
log.WithFields(logrus.Fields{
"prefix": "pub-sub",
}).Info("Reloading endpoints")
ReloadURLStructure()
}