提交 5628fbca authored 作者: gukai's avatar gukai

增加单条快速推送topic

上级 76ac5d27
......@@ -3,6 +3,7 @@ package notify
import (
"encoding/json"
"errors"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/util/gconv"
"gitlab.jxhh.com/stbz/library.git/logs"
......@@ -23,6 +24,8 @@ const (
NotifyTopic = "notifyMessage"
//API请求日志
ApiRequestTopic = "apiRequest"
//通知消息系统topic
SingleTopic = "singleMessage"
//消息类型
......@@ -179,44 +182,18 @@ func (p *NsqProducer) NotifyMessage(notifyMessage *NotifyMessage) (err error) {
randNums += strconv.Itoa(r.Intn(9))
}
notifyMessage.ID = gconv.Int(gconv.String(time.Now().UnixNano()/1e6) + randNums)
notifyMsg := NotifyTopic
if notifyMessage.AppID > 0 {
notifyMsg = SingleTopic
}
jsonBytes, _ := json.Marshal(notifyMessage)
err = NsqProducers.Publish(NotifyTopic, string(jsonBytes))
err = NsqProducers.Publish(notifyMsg, gjson.New(notifyMessage).MustToJsonString())
if !logs.CheckErr(err, "NotifyMessage") {
logs.Info("NotifyMessage", "消息内容:【%v】", string(jsonBytes))
logs.Info("NotifyMessage", "消息内容:【%v】", gjson.New(notifyMessage).MustToJsonString())
}
return
}
/*
推送通知到服务系统系统 20220114 gk
*****************************************************
*******注意:该方法目前只有message-server使用 ***********
*****************************************************
*/
func (p *NsqProducer) NotifyServer(notifyServer *NotifyServer) (err error) {
jsonBytes, _ := json.Marshal(notifyServer)
var pushTopic string
switch notifyServer.MsgType / 100 % 10 {
case 1:
pushTopic = MsgGoodsTopic
case 2:
pushTopic = MsgOrderTopic
case 3:
pushTopic = MsgOrderTopic
}
if pushTopic == "" {
return
}
err = NsqProducers.Publish(NotifyTopic, string(jsonBytes))
if !logs.CheckErr(err, "NotifyServer") {
logs.Info("NotifyServer", "消息内容:【%v】", string(jsonBytes))
}
return
}
/*
api请求日志 20220310 gk
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论