forked from TykTechnologies/tyk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reload_signal.go
40 lines (34 loc) · 914 Bytes
/
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
package main
import (
"encoding/json"
"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.Error("Connection to Redis failed: ", err)
time.Sleep(10 * time.Second)
log.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.Info("Reload signal received, reloading endpoints")
ReloadURLStructure()
}