Explorar el Código

处理银行服务相关业务收不到回复的问题

zhou.xiaoning hace 3 años
padre
commit
527541759e
Se han modificado 3 ficheros con 18 adiciones y 1 borrados
  1. 9 0
      initialize/rabbitmq.go
  2. 0 1
      main.go
  3. 9 0
      service/mq/mq.go

+ 9 - 0
initialize/rabbitmq.go

@@ -50,6 +50,13 @@ func (t *MQProc) Process(topic, queuename string, msg *[]byte) {
 		// 尝试获取对应异步任务
 		if client, exists := global.M2A_Clients[int(sessionId)]; exists {
 			key := fmt.Sprintf("%v_%v_%v", sessionId, funcode, serialNumber)
+			// 银行服务相关的回复流水号是错误的,所以需要特殊处理
+			if int(funcode) == global.T2bBankSignRsp ||
+				int(funcode) == global.T2bBankCancelSignRsp ||
+				int(funcode) == global.T2bBankWithdrawRsp ||
+				int(funcode) == global.T2bBankDepositRsp {
+				key = fmt.Sprintf("%v_%v", sessionId, funcode)
+			}
 			asyncTask := client.GetAsyncTask(key)
 			if asyncTask != nil {
 				rspData := string(*bytes)
@@ -82,6 +89,8 @@ func (t *MQProc) getRspProtobuf(msg *[]byte) (funcode uint32, sessionId uint32,
 	sessionId = utils.BytesToUint32((*msg)[4:8])
 	b := (*msg)[8:]
 
+	global.M2A_LOG.Info("收到总线订阅消息", zap.Any("funcode", funcode), zap.Any("sessionId", sessionId), zap.Any("len", len(b)))
+
 	switch int(funcode) {
 	case global.ModifyPwdRsp: // 修改账户密码应答
 		var p pb.ModifyPwdRsp

+ 0 - 1
main.go

@@ -16,7 +16,6 @@ import (
 // @name                       x-token
 // @BasePath                   /api
 func main() {
-
 	// 初始化Viper
 	global.M2A_VP = core.Viper()
 

+ 9 - 0
service/mq/mq.go

@@ -46,6 +46,13 @@ func SendMQ(c *gin.Context, req *request.MQBodyReq) (err error) {
 
 	// 创建异步任务
 	key := fmt.Sprintf("%v_%v_%v", client.SessionID, req.FunCodeRsp, serialNumber)
+	// 银行服务相关的回复流水号是错误的,所以需要特殊处理
+	if int(req.FunCodeReq) == global.T2bBankSignReq ||
+		int(req.FunCodeReq) == global.T2bBankCancelSignReq ||
+		int(req.FunCodeReq) == global.T2bBankWithdrawReq ||
+		int(req.FunCodeReq) == global.T2bBankDepositReq {
+		key = fmt.Sprintf("%v_%v", client.SessionID, req.FunCodeRsp)
+	}
 	asyncTask := global.AsyncTask{
 		FuncodeRsp:   req.FunCodeRsp,
 		SerialNumber: serialNumber,
@@ -76,6 +83,8 @@ func SendMQ(c *gin.Context, req *request.MQBodyReq) (err error) {
 	case r := <-asyncTask.Rsp: // 总线回复
 		rsp.OkWithData(r, c)
 	case <-time.After(time.Second * 30): // 超时
+		// 删除对应异步任务
+		client.DeleteAsyncTask(key)
 		rsp.FailWithMessage("业务超时", c)
 	}
 	asyncTask.Finish()