nats discovery
This commit is contained in:
19
tools/api.go
19
tools/api.go
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/config"
|
||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
/*
|
||||
@@ -70,6 +71,24 @@ 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]interface{})) {
|
||||
nats := NewNATSCaller()
|
||||
go nats.ListenNats(DISCOVERY.GenerateKey("api"), exec)
|
||||
}
|
||||
|
||||
func (a *API) SubscribeRouter() {
|
||||
nats := NewNATSCaller()
|
||||
discovery := map[string]interface{}{}
|
||||
for _, info := range beego.BeeApp.Handlers.GetAllControllerInfo() {
|
||||
methods := []string{}
|
||||
for k := range info.GetMethod() {
|
||||
methods = append(methods, k)
|
||||
}
|
||||
discovery[info.GetPattern()] = methods
|
||||
}
|
||||
nats.SetNATSPub("api", DISCOVERY, discovery)
|
||||
}
|
||||
|
||||
// CheckRemotePeer checks the state of a remote peer
|
||||
func (a *API) CheckRemotePeer(url string) (State, map[string]int) {
|
||||
// Check if the database is up
|
||||
|
||||
Reference in New Issue
Block a user