-
Notifications
You must be signed in to change notification settings - Fork 2
/
router.go
54 lines (46 loc) · 1.2 KB
/
router.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
51
52
53
54
package applog_endpoint
import (
"github.com/ActiveState/log"
"github.com/ActiveState/logyard-apps/applog_endpoint/config"
"github.com/apcera/nats"
"strings"
)
var NATS *nats.EncodedConn
type routerRegisterInfo struct {
Host string `json:"host"`
Port int `json:"port"`
URIs []string `json:"uris"`
Tags struct {
Component string `json:"string"`
} `json:"tags"`
}
type applogEndpointConfigStruct struct {
Hostname string `json:"hostname"`
}
func getApplogEndpointUri() string {
uri := config.GetConfig().Hostname
if uri == "" {
clusterConfig := config.GetClusterConfig()
uri = strings.Replace(clusterConfig.Endpoint, "api.", "logs.", 1)
}
return uri
}
func newRouterRegisterInfo() *routerRegisterInfo {
info := new(routerRegisterInfo)
info.Host = config.NodeIPMust()
info.Port = PORT
info.URIs = []string{getApplogEndpointUri()}
info.Tags.Component = COMPONENT
return info
}
func routerAdvertise(m interface{}) {
info := newRouterRegisterInfo()
log.Infof("Advertising ourself to router: %+v (router.start? %+v)",
info, m)
NATS.Publish("router.register", info)
}
func RouterMain() {
NATS = config.NewNatsClient(3)
routerAdvertise(nil)
NATS.Subscribe("router.start", routerAdvertise)
}