-
Notifications
You must be signed in to change notification settings - Fork 19
/
Zookeeper.go
51 lines (37 loc) · 921 Bytes
/
Zookeeper.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
package main
import (
"github.com/samuel/go-zookeeper/zk"
"strings"
"time"
)
func must(err error) {
if err != nil {
panic(err)
}
}
type ZookeeperClient struct {
conString string
}
func (z ZookeeperClient) connect() *zk.Conn {
zks := strings.Split(z.conString, ",")
conn, _, err := zk.Connect(zks, (60 * time.Second))
must(err)
return conn
}
/**
* Watches a Zookeeper node continuously in a loop. When a watch fires, the new config is rendered.
* When first registering the watch, the initial payload is also rendered
*/
func (z ZookeeperClient) watchLocalProxyConfig(conn *zk.Conn, path string) {
go func() {
for {
payload, _, watch, err := conn.GetW(path)
must(err)
RenderLocalProxyConfig(payload, ConfigObj)
// block till event fires
event := <- watch
log.Info("Received Zookeeper event: " + event.Type.String())
RenderLocalProxyConfig(payload,ConfigObj)
}
}()
}