Structured NATS
This commit is contained in:
19
tools/api.go
19
tools/api.go
@@ -61,10 +61,8 @@ func (s State) String() string {
|
||||
type API struct{}
|
||||
|
||||
func (a *API) Discovered(infos []*beego.ControllerInfo) {
|
||||
respondToDiscovery := func(m map[string]string) {
|
||||
if len(m) == 0 {
|
||||
a.SubscribeRouter(infos)
|
||||
}
|
||||
respondToDiscovery := func(m NATSResponse) {
|
||||
a.SubscribeRouter(infos)
|
||||
}
|
||||
a.ListenRouter(respondToDiscovery)
|
||||
a.SubscribeRouter(infos)
|
||||
@@ -91,8 +89,8 @@ func (a *API) GetState() (State, int, error) {
|
||||
return ALIVE, 200, nil // If everything is up, return alive
|
||||
}
|
||||
|
||||
func (a *API) ListenRouter(exec func(msg map[string]string)) {
|
||||
go NewNATSCaller().ListenNats(map[NATSMethod]func(msg map[string]string){
|
||||
func (a *API) ListenRouter(exec func(msg NATSResponse)) {
|
||||
go NewNATSCaller().ListenNats(map[NATSMethod]func(msg NATSResponse){
|
||||
DISCOVERY: exec,
|
||||
})
|
||||
}
|
||||
@@ -113,7 +111,14 @@ func (a *API) SubscribeRouter(infos []*beego.ControllerInfo) {
|
||||
}
|
||||
}
|
||||
}
|
||||
go nats.SetNATSPub(DISCOVERY, discovery)
|
||||
b, _ := json.Marshal(discovery)
|
||||
|
||||
go nats.SetNATSPub(DISCOVERY, NATSResponse{
|
||||
FromApp: beego.AppPath,
|
||||
Datatype: -1,
|
||||
Method: int(DISCOVERY),
|
||||
Payload: b,
|
||||
})
|
||||
}
|
||||
|
||||
// CheckRemotePeer checks the state of a remote peer
|
||||
|
||||
Reference in New Issue
Block a user