mirror of
https://github.com/kongyuebin1/dongfeng-pay.git
synced 2025-08-18 11:41:59 +08:00
修改网关代码的结构,调整了逻辑,删除了许多无用的代码
This commit is contained in:
43
gateway/message/init.go
Normal file
43
gateway/message/init.go
Normal file
@@ -0,0 +1,43 @@
|
||||
/***************************************************
|
||||
** @Desc : This file for ...
|
||||
** @Time : 2019/11/6 11:43
|
||||
** @Author : yuebin
|
||||
** @File : active_mq
|
||||
** @Last Modified by : yuebin
|
||||
** @Last Modified time: 2019/11/6 11:43
|
||||
** @Software: GoLand
|
||||
****************************************************/
|
||||
package message
|
||||
|
||||
import (
|
||||
"gateway/conf"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/go-stomp/stomp"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
//解决第一个问题的代码
|
||||
var activeConn *stomp.Conn
|
||||
|
||||
var options = []func(*stomp.Conn) error{
|
||||
//设置读写超时,超时时间为1个小时
|
||||
stomp.ConnOpt.HeartBeat(7200*time.Second, 7200*time.Second),
|
||||
stomp.ConnOpt.HeartBeatError(360 * time.Second),
|
||||
}
|
||||
|
||||
func init() {
|
||||
address := conf.GetMQAddress()
|
||||
|
||||
conn, err := stomp.Dial("tcp", address, options...)
|
||||
if err != nil {
|
||||
logs.Error("链接active mq 失败:", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
activeConn = conn
|
||||
}
|
||||
|
||||
func GetActiveMQConn() *stomp.Conn {
|
||||
return activeConn
|
||||
}
|
33
gateway/message/send_message.go
Normal file
33
gateway/message/send_message.go
Normal file
@@ -0,0 +1,33 @@
|
||||
/***************************************************
|
||||
** @Desc : This file for ...
|
||||
** @Time : 2019/11/21 15:53
|
||||
** @Author : yuebin
|
||||
** @File : send_message
|
||||
** @Last Modified by : yuebin
|
||||
** @Last Modified time: 2019/11/21 15:53
|
||||
** @Software: GoLand
|
||||
****************************************************/
|
||||
package message
|
||||
|
||||
import (
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"os"
|
||||
)
|
||||
|
||||
func SendMessage(topic, message string) {
|
||||
|
||||
conn := GetActiveMQConn()
|
||||
|
||||
if conn == nil {
|
||||
logs.Error("send message get Active mq fail")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
err := conn.Send(topic, "text/plain", []byte(message))
|
||||
|
||||
if err != nil {
|
||||
logs.Error("发送消息给activeMQ失败, message=", message)
|
||||
} else {
|
||||
logs.Info("发送消息给activeMQ成功,message=", message)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user