Structured NATS
This commit is contained in:
@@ -2,7 +2,6 @@ package tools
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -67,7 +66,7 @@ func NewNATSCaller() *natsCaller {
|
||||
|
||||
// on workflows' scheduling. Messages must contain
|
||||
// workflow execution ID, to allow retrieval of execution infos
|
||||
func (s *natsCaller) ListenNats(execs map[NATSMethod]func(map[string]string)) {
|
||||
func (s *natsCaller) ListenNats(execs map[NATSMethod]func(NATSResponse)) {
|
||||
log := logs.GetLogger()
|
||||
if config.GetConfig().NATSUrl == "" {
|
||||
log.Error().Msg(" -> NATS_SERVER is not set")
|
||||
@@ -121,7 +120,7 @@ func (o *natsCaller) SetNATSPub(method NATSMethod, data NATSResponse) string {
|
||||
// on workflows' scheduling. Messages must contain
|
||||
// workflow execution ID, to allow retrieval of execution infos
|
||||
func (o *natsCaller) listenForChange(logger zerolog.Logger, nc *nats.Conn, natsTools NATSMethod,
|
||||
function func(map[string]string), wg *sync.WaitGroup) {
|
||||
function func(NATSResponse), wg *sync.WaitGroup) {
|
||||
defer wg.Done()
|
||||
ch := make(chan *nats.Msg, 64)
|
||||
logger.Info().Msg("Listening to " + natsTools.GenerateKey())
|
||||
@@ -132,9 +131,9 @@ func (o *natsCaller) listenForChange(logger zerolog.Logger, nc *nats.Conn, natsT
|
||||
defer subs.Unsubscribe()
|
||||
|
||||
for msg := range ch {
|
||||
map_mess := map[string]string{}
|
||||
json.Unmarshal(msg.Data, &map_mess)
|
||||
fmt.Println("Catching " + natsTools.String() + " workflow... " + map_mess["id"])
|
||||
function(map_mess)
|
||||
var resp NATSResponse
|
||||
json.Unmarshal(msg.Data, &resp)
|
||||
logger.Info().Msg("Catching " + natsTools.String() + "... " + resp.FromApp + " - " + resp.Datatype.String())
|
||||
function(resp)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user