nats discovery

This commit is contained in:
mr
2024-10-17 13:53:57 +02:00
parent 9654d59fc0
commit dbcd9cf004
2 changed files with 48 additions and 0 deletions

View File

@@ -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