github.com/mdaxf/iac@v0.0.0-20240519030858-58a061660378/engine/function/sendmsgbymqtt.go (about) 1 package funcs 2 3 import ( 4 // "context" 5 6 "fmt" 7 "time" 8 ) 9 10 type SendMessagebyMQTT struct { 11 } 12 13 func (w *SendMessagebyMQTT) Execute(f *Funcs) { 14 startTime := time.Now() 15 defer func() { 16 elapsed := time.Since(startTime) 17 f.iLog.PerformanceWithDuration("engine.funcs.SendMessagebyMQTT.Execute", elapsed) 18 }() 19 defer func() { 20 if err := recover(); err != nil { 21 f.iLog.Error(fmt.Sprintf("There is error to engine.funcs.SendMessagebyMQTT.Execute with error: %s", err)) 22 f.CancelExecution(fmt.Sprintf("There is error to engine.funcs.SendMessagebyMQTT.Execute with error: %s", err)) 23 f.ErrorMessage = fmt.Sprintf("There is error to engine.funcs.SendMessagebyMQTT.Execute with error: %s", err) 24 return 25 } 26 }() 27 28 f.iLog.Debug(fmt.Sprintf("SendMessagebyMQTT Execute: %v", f)) 29 30 namelist, valuelist, _ := f.SetInputs() 31 f.iLog.Debug(fmt.Sprintf("SendMessagebyMQTT Execute: %v, %v", namelist, valuelist)) 32 //activeMQCfg := "" 33 Topic := "" 34 data := make(map[string]interface{}) 35 for i, name := range namelist { 36 if name == "Topic" { 37 Topic = valuelist[i] 38 39 continue 40 } else if name == "ActiveMQ" { 41 // activeMQCfg = valuelist[i] 42 } 43 data[name] = valuelist[i] 44 } 45 46 if Topic == "" { 47 f.iLog.Error(fmt.Sprintf("SendMessagebyActiveMQ validate wrong: %v", "Topic is empty")) 48 return 49 } 50 51 // get activeMQ connection 52 53 // product the data 54 55 // send the data to activeMQ 56 57 }