zhou.xiaoning il y a 3 ans
Parent
commit
1880051658
3 fichiers modifiés avec 15 ajouts et 11 suppressions
  1. 6 5
      initialize/rabbitmq.go
  2. 8 6
      model/mq/request/mq.go
  3. 1 0
      service/mq/mq.go

+ 6 - 5
initialize/rabbitmq.go

@@ -40,11 +40,11 @@ type MQProc struct{}
 
 // process 消息处理接口
 func (t *MQProc) Process(topic, queuename string, msg *[]byte) {
-	info := fmt.Sprintf("rabbitmq receive message from: topic[%s] queue[%s] contentLen[%d]",
-		topic,
-		queuename,
-		len(string(*msg)))
-	global.M2A_LOG.Info(info)
+	// info := fmt.Sprintf("rabbitmq receive message from: topic[%s] queue[%s] contentLen[%d]",
+	// 	topic,
+	// 	queuename,
+	// 	len(string(*msg)))
+	// global.M2A_LOG.Info(info)
 
 	if funcode, sessionId, bytes, serialNumber, err := t.getRspProtobuf(msg); err == nil && bytes != nil {
 		// 尝试获取对应异步任务
@@ -63,6 +63,7 @@ func (t *MQProc) Process(topic, queuename string, msg *[]byte) {
 					}
 				}
 				// 给客户端回调
+				global.M2A_LOG.Info("[S->C]", zap.Any("funcode", funcode), zap.Any("data", string(rspData)))
 				r := rsp.MQBodyRsp{
 					FunCode:     funcode,
 					IsEncrypted: asyncTask.IsEncrypted,

+ 8 - 6
model/mq/request/mq.go

@@ -317,12 +317,6 @@ func (r *MQBodyReq) GetProtoBytes(serialNumber *uint32) (bytes *[]byte, err erro
 			bytes = &b
 		}
 	case global.GoodsFavoriteOperateReq:
-		reg, _ := regexp.Compile(`"[0-9]{19}"`)
-		all := reg.FindAll([]byte(data), -1)
-		for _, i := range all {
-			r := strings.Replace(string(i), "\"", "", -1)
-			data = strings.Replace(data, string(i), r, -1)
-		}
 		m := pb.GoodsFavoriteOperateReq{}
 		if err = r.reflect(data, &m); err != nil {
 			return
@@ -508,6 +502,14 @@ func (r *MQBodyReq) GetProtoBytes(serialNumber *uint32) (bytes *[]byte, err erro
 }
 
 func (r *MQBodyReq) reflect(data string, m proto.Message) (err error) {
+	// 由于JS对Long类型支持不佳,故让小程序端在使用单号时以字符串发过来,服务这边会自动把19位数字的字符串转化为数字
+	reg, _ := regexp.Compile(`"[0-9]{19}"`)
+	all := reg.FindAll([]byte(data), -1)
+	for _, i := range all {
+		r := strings.Replace(string(i), "\"", "", -1)
+		data = strings.Replace(data, string(i), r, -1)
+	}
+
 	if e := jsonpb.UnmarshalString(data, m); e != nil {
 		global.M2A_LOG.Error(e.Error(), zap.Error(e))
 		err = errors.New("业务数据装箱失败")

+ 1 - 0
service/mq/mq.go

@@ -63,6 +63,7 @@ func SendMQ(c *gin.Context, req *request.MQBodyReq) (err error) {
 	}
 
 	// 向总线发送业务信息
+	global.M2A_LOG.Info("[C->S]", zap.Any("funcode", req.FunCodeReq), zap.Any("data", string(*bytes)))
 	packet := &global.MQPacket{
 		FunCode:   req.FunCodeReq,
 		SessionId: uint32(claims.SessionID),