123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- package NatsServer
- import (
- "Cold_mqtt/lib"
- "Cold_mqtt/logs"
- "Cold_mqtt/models/Account"
- "Cold_mqtt/models/Warning"
- "github.com/vmihailenco/msgpack/v5"
- "strconv"
- "strings"
- "time"
- )
- func App_Warn(Company_Charging_r Account.Company, Warning_r *Warning.Warning, Uuid string, Dataj string) {
- logs.Println("Nats =>", lib.FuncName(), Uuid, Dataj)
- type Ali_Message struct {
- Uuid string
- Data string
- }
- b, err := msgpack.Marshal(&Ali_Message{
- Uuid: Uuid,
- Data: Dataj,
- })
- if err != nil {
- logs.Println("App_Warn", err)
- return
- }
- cun_x := 0
- Data := ""
- breakHere:
- cun_x++
- // 控制发送
- if cun_x > 3 {
- // 添加
- Warning_r_e := Warning.Warning{}
- Warning_r_e.T_pid = 0
- Warning_r_e.T_tp = 1014
- Warning_r_e.T_D_name = "App_Warn通讯"
- Warning_r_e.T_Remark = "App_Warn通讯 异常!"
- Warning_r_e.T_Log = Data
- Warning_r_e.T_State = 3
- Warning_r_e.T_Ut = time.Now()
- //WarningNotice.WarningToAdminId(&Warning_r_e, []int{1}) // 发送给 绑定公司管理员
- // 添加报警
- Warning.Add_Warning(Warning_r_e)
- logs.PrintlnError("App通知", "App_Warn通讯 异常!")
- // 达到数量上线跳出
- return
- }
- // 请求-响应, 向 test3 发布一个 `help me` 请求数据,设置超时间3秒,如果有多个响应,只接收第一个收到的消息
- msg, err := lib.Nats.Request("App_Warn", b, 60*time.Second)
- if err != nil {
- logs.PrintlnError("App_Warn %s", err.Error())
- Warning.Add_Warning_Log(Warning_r, "---->App_Warn服务发送超时 异常!尝试发送 "+strconv.Itoa(cun_x)+" 次 ["+time.Now().Format("15:04:05")+"]\n")
- Data = "App_Warn服务通讯 异常!Nats Err!"
- time.Sleep(time.Second * time.Duration(cun_x))
- goto breakHere // 跳转到标签
- }
- Data = string(msg.Data)
- logs.Println("App_Warn => : %s\n", Data)
- if !strings.Contains(Data, "成功") {
- Warning.Add_Warning_Log(Warning_r, "---->App_Warn服务发送失败!["+Data+"]!尝试发送 "+strconv.Itoa(cun_x)+" 次 ["+time.Now().Format("15:04:05")+"]\n")
- time.Sleep(time.Second * time.Duration(cun_x))
- goto breakHere // 跳转到标签
- }
- Warning.Add_Warning_Log(Warning_r, "->"+Data+"\n")
- }
|