diff --git a/comm/core.go b/comm/core.go index bc07dafa7..7cbc4bf3d 100644 --- a/comm/core.go +++ b/comm/core.go @@ -54,6 +54,7 @@ type IUserSession interface { Bind(uid string, wokerId string) (err error) UnBind() (err error) SendMsg(mainType, subType string, msg proto.Message) (err error) + Polls() []*pb.UserMessage Close() (err error) ToString() string } diff --git a/comm/usersession.go b/comm/usersession.go index d8ff86e01..82fc50420 100644 --- a/comm/usersession.go +++ b/comm/usersession.go @@ -89,17 +89,24 @@ func (this *UserSession) UnBind() (err error) { //向用户发送消息 func (this *UserSession) SendMsg(mainType, subType string, msg proto.Message) (err error) { - reply := &pb.RPCMessageReply{} - data, _ := anypb.New(msg) log.Debugf("SendMsg to SessionId:[%s] UserId:[%s] Data: %v", this.UserId, msg) - if err := this.service.RpcCall(context.Background(), fmt.Sprintf("%s/%s", Service_Gateway, this.GatewayServiceId), string(Rpc_GatewayAgentSendMsg), &pb.AgentSendMessageReq{ - UserSessionId: this.SessionId, - MainType: mainType, - SubType: subType, - Data: data, - }, reply); err != nil { - log.Errorf("SendMsg:%s UserSession:%s UserId:%s err:%v", mainType, this.SessionId, this.UserId, err) - } + data, _ := anypb.New(msg) + this.msgqueue = append(this.msgqueue, &pb.UserMessage{ + MainType: mainType, + SubType: subType, + Data: data, + }) + // reply := &pb.RPCMessageReply{} + // data, _ := anypb.New(msg) + // log.Debugf("SendMsg to SessionId:[%s] UserId:[%s] Data: %v", this.UserId, msg) + // if err := this.service.RpcCall(context.Background(), fmt.Sprintf("%s/%s", Service_Gateway, this.GatewayServiceId), string(Rpc_GatewayAgentSendMsg), &pb.AgentSendMessageReq{ + // UserSessionId: this.SessionId, + // MainType: mainType, + // SubType: subType, + // Data: data, + // }, reply); err != nil { + // log.Errorf("SendMsg:%s UserSession:%s UserId:%s err:%v", mainType, this.SessionId, this.UserId, err) + // } return } @@ -114,6 +121,13 @@ func (this *UserSession) Close() (err error) { return } +//清空消息队列 +func (this *UserSession) Polls() []*pb.UserMessage { + msgs := this.msgqueue + this.msgqueue = this.msgqueue[:0] + return msgs +} + //打印日志需要 func (this *UserSession) ToString() string { return fmt.Sprintf("SessionId:%s UserId:%s GatewayServiceId:%s", this.SessionId, this.UserId, this.GatewayServiceId) diff --git a/modules/friend/api.go b/modules/friend/api.go index 9bb5c5785..b9e8176f6 100644 --- a/modules/friend/api.go +++ b/modules/friend/api.go @@ -18,12 +18,12 @@ const ( ) type apiComp struct { - modules.MComp_GateComp + modules.MCompGate module *Friend } func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { - this.MComp_GateComp.Init(service, module, comp, options) + this.MCompGate.Init(service, module, comp, options) this.module = module.(*Friend) return } diff --git a/services/comp_gateroute.go b/services/comp_gateroute.go index 566991e05..170e64012 100644 --- a/services/comp_gateroute.go +++ b/services/comp_gateroute.go @@ -143,8 +143,9 @@ func (this *SCompGateRoute) ReceiveMsg(ctx context.Context, args *pb.AgentMessag reply.Code = errcode reply.ErrorMessage = pb.GetErrorCodeMsg(errcode) return nil + } else { + reply.Reply = session.Polls() } - } else { //未找到消息处理函数 reply.Code = pb.ErrorCode_ReqParameterError }