补充用户消息处理函数的注释
This commit is contained in:
parent
e464879799
commit
5b914746e5
@ -119,7 +119,7 @@ func (this *SComp_GateRouteComp) RegisterRouteCheck(methodName string, comp refl
|
|||||||
|
|
||||||
//Rpc_GatewayRoute服务接口的接收函数
|
//Rpc_GatewayRoute服务接口的接收函数
|
||||||
func (this *SComp_GateRouteComp) ReceiveMsg(ctx context.Context, args *pb.AgentMessage, reply *pb.RPCMessageReply) error {
|
func (this *SComp_GateRouteComp) ReceiveMsg(ctx context.Context, args *pb.AgentMessage, reply *pb.RPCMessageReply) error {
|
||||||
defer func() {
|
defer func() { //程序异常 收集异常信息传递给前端显示
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
buf := make([]byte, 1024)
|
buf := make([]byte, 1024)
|
||||||
l := runtime.Stack(buf, false)
|
l := runtime.Stack(buf, false)
|
||||||
@ -129,25 +129,30 @@ func (this *SComp_GateRouteComp) ReceiveMsg(ctx context.Context, args *pb.AgentM
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
log.Debugf("SComp_GateRouteComp ReceiveMsg agent:%s uId:%s MessageDistribution msg:%s", args.UserSessionId, args.UserId, args.Method)
|
log.Debugf("SComp_GateRouteComp ReceiveMsg agent:%s uId:%s MessageDistribution msg:%s", args.UserSessionId, args.UserId, args.Method)
|
||||||
|
//获取用户消息处理函数
|
||||||
this.mrlock.RLock()
|
this.mrlock.RLock()
|
||||||
msghandle, ok := this.msghandles[args.Method]
|
msghandle, ok := this.msghandles[args.Method]
|
||||||
msgcheck := this.msgcheck[args.Method]
|
msgcheck := this.msgcheck[args.Method]
|
||||||
this.mrlock.RUnlock()
|
this.mrlock.RUnlock()
|
||||||
if ok {
|
if ok {
|
||||||
|
//封装用户会话
|
||||||
session := comm.NewUserSession(this.service, args.Ip, args.UserSessionId, args.GatewayServiceId, args.UserId)
|
session := comm.NewUserSession(this.service, args.Ip, args.UserSessionId, args.GatewayServiceId, args.UserId)
|
||||||
|
//序列化用户消息对象
|
||||||
msg := reflect.New(msghandle.msgType.Elem()).Interface()
|
msg := reflect.New(msghandle.msgType.Elem()).Interface()
|
||||||
if err := ptypes.UnmarshalAny(args.Message, msg.(proto.Message)); err != nil {
|
if err := ptypes.UnmarshalAny(args.Message, msg.(proto.Message)); err != nil {
|
||||||
log.Errorf("UserMessage:%s Unmarshal err:%v", args.Method, err)
|
log.Errorf("UserMessage:%s Unmarshal err:%v", args.Method, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
returnValues := msgcheck.fn.Func.Call([]reflect.Value{msgcheck.rcvr, reflect.ValueOf(session), reflect.ValueOf(msg)})
|
|
||||||
// The return value for the method is an error.
|
//调用校验接口
|
||||||
code := returnValues[1].Interface().(comm.ErrorCode)
|
checkreturn := msgcheck.fn.Func.Call([]reflect.Value{msgcheck.rcvr, reflect.ValueOf(session), reflect.ValueOf(msg)})
|
||||||
|
//读取校验结果 有错误直接返回错误码给用户
|
||||||
|
code := checkreturn[1].Interface().(comm.ErrorCode)
|
||||||
if code.Code != pb.ErrorCode_Success {
|
if code.Code != pb.ErrorCode_Success {
|
||||||
log.Errorf("HandleUserMsg:%s msg:%v code:%d", args.Method, msg, code)
|
log.Errorf("HandleUserMsg:%s msg:%v code:%d", args.Method, msg, code)
|
||||||
reply.Code = code.Code
|
reply.Code = code.Code
|
||||||
reply.Message = pb.GetErrorCodeMsg(code.Code)
|
reply.Message = pb.GetErrorCodeMsg(code.Code)
|
||||||
if code.Data != nil {
|
if code.Data != nil { //处理错误附加数据 采用json 序列化为string
|
||||||
if d, err := jsoniter.Marshal(code.Data); err != nil {
|
if d, err := jsoniter.Marshal(code.Data); err != nil {
|
||||||
log.Errorf("HandleUserMsg:%s msg:%v code:%d err:%v", args.Method, msg, code, err)
|
log.Errorf("HandleUserMsg:%s msg:%v code:%d err:%v", args.Method, msg, code, err)
|
||||||
return nil
|
return nil
|
||||||
@ -157,16 +162,18 @@ func (this *SComp_GateRouteComp) ReceiveMsg(ctx context.Context, args *pb.AgentM
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
result := returnValues[0].Interface().(map[string]interface{})
|
//校验结果成功 处理临时数据转移
|
||||||
returnValues = msghandle.fn.Func.Call([]reflect.Value{msghandle.rcvr, reflect.ValueOf(session), reflect.ValueOf(result), reflect.ValueOf(msg)})
|
result := checkreturn[0].Interface().(map[string]interface{})
|
||||||
errcode := pb.ErrorCode(returnValues[0].Int())
|
//调用用户处理函数
|
||||||
if errcode != pb.ErrorCode_Success {
|
handlereturn := msghandle.fn.Func.Call([]reflect.Value{msghandle.rcvr, reflect.ValueOf(session), reflect.ValueOf(result), reflect.ValueOf(msg)})
|
||||||
|
errcode := pb.ErrorCode(handlereturn[0].Int())
|
||||||
|
if errcode != pb.ErrorCode_Success { //处理返货错误码 返回用户错误信息
|
||||||
log.Errorf("HandleUserMsg:%s msg:%v code:%d", args.Method, msg, code)
|
log.Errorf("HandleUserMsg:%s msg:%v code:%d", args.Method, msg, code)
|
||||||
reply.Code = errcode
|
reply.Code = errcode
|
||||||
reply.Message = pb.GetErrorCodeMsg(errcode)
|
reply.Message = pb.GetErrorCodeMsg(errcode)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
} else {
|
} else { //未找到消息处理函数
|
||||||
reply.Code = pb.ErrorCode_ReqParameterError
|
reply.Code = pb.ErrorCode_ReqParameterError
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user