NATS_SERVER

This commit is contained in:
mr
2026-02-05 14:10:48 +01:00
parent 9e30133628
commit 425cd2a9ba

View File

@@ -2,6 +2,7 @@ package tools
import ( import (
"encoding/json" "encoding/json"
"fmt"
"strings" "strings"
"sync" "sync"
"time" "time"
@@ -103,12 +104,14 @@ func (o *natsCaller) SetNATSPub(method NATSMethod, data NATSResponse) string {
for { for {
nc, err := nats.Connect(config.GetConfig().NATSUrl) nc, err := nats.Connect(config.GetConfig().NATSUrl)
if err != nil { if err != nil {
fmt.Println("NATS Connect err", err)
time.Sleep(1 * time.Minute) time.Sleep(1 * time.Minute)
continue continue
} }
defer nc.Close() defer nc.Close()
js, err := json.Marshal(data) js, err := json.Marshal(data)
if err != nil { if err != nil {
fmt.Println("NATS Marshal err", err)
return " -> " + err.Error() return " -> " + err.Error()
} }
err = nc.Publish(method.GenerateKey(), js) // Publish the message on the NATS server with a channel name based on the data name (or whatever start) and the method err = nc.Publish(method.GenerateKey(), js) // Publish the message on the NATS server with a channel name based on the data name (or whatever start) and the method