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 (
"encoding/json"
"fmt"
"strings"
"sync"
"time"
@@ -103,12 +104,14 @@ func (o *natsCaller) SetNATSPub(method NATSMethod, data NATSResponse) string {
for {
nc, err := nats.Connect(config.GetConfig().NATSUrl)
if err != nil {
fmt.Println("NATS Connect err", err)
time.Sleep(1 * time.Minute)
continue
}
defer nc.Close()
js, err := json.Marshal(data)
if err != nil {
fmt.Println("NATS Marshal err", err)
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