From ca0a418b4fea675bc35a5eae21640feca1de0ad5 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Wed, 15 Jun 2022 11:12:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=94=A8=E6=88=B7=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E7=BD=91=E5=85=B3=E5=A4=84=E7=90=86=E6=B5=81=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/core.go | 2 ++ modules/pack/pack_test.go | 23 ++++++++++++++++------- services/comp_gateroute.go | 8 ++++---- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/comm/core.go b/comm/core.go index 9d6d8e384..8c515c501 100644 --- a/comm/core.go +++ b/comm/core.go @@ -1,6 +1,7 @@ package comm import ( + "context" "go_dreamfactory/pb" "reflect" @@ -52,6 +53,7 @@ const ( // 服务网关组件接口定义 type ISC_GateRouteComp interface { core.IServiceComp + ReceiveMsg(ctx context.Context, args *pb.AgentMessage, reply *pb.RPCMessageReply) error RegisterRoute(methodName string, comp reflect.Value, msg reflect.Type, fn reflect.Method) RegisterRouteCheck(methodName string, comp reflect.Value, msg reflect.Type, fn reflect.Method) } diff --git a/modules/pack/pack_test.go b/modules/pack/pack_test.go index d17b20e44..c0e29a8fa 100644 --- a/modules/pack/pack_test.go +++ b/modules/pack/pack_test.go @@ -1,11 +1,14 @@ package pack import ( + "context" "fmt" + "go_dreamfactory/comm" "go_dreamfactory/lego" "go_dreamfactory/lego/base/rpcx" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" + "go_dreamfactory/pb" "go_dreamfactory/services" "go_dreamfactory/sys/cache" "go_dreamfactory/sys/configure" @@ -13,6 +16,8 @@ import ( "os" "testing" "time" + + "github.com/golang/protobuf/ptypes" ) func newService(ops ...rpcx.Option) core.IService { @@ -46,27 +51,31 @@ func (this *TestService) InitSys() { } } +var service core.IService +var s_gateComp comm.ISC_GateRouteComp = services.NewGateRouteComp() var module = new(Pack) //测试环境下初始化db和cache 系统 func TestMain(m *testing.M) { - s := newService( + service = newService( rpcx.SetConfPath("../../bin/conf/worker_1.yaml"), rpcx.SetVersion("1.0.0.0"), ) - s.OnInstallComp( //装备组件 - services.NewGateRouteComp(), //此服务需要接受用户的消息 需要装备网关组件 + service.OnInstallComp( //装备组件 + s_gateComp, //此服务需要接受用户的消息 需要装备网关组件 ) go func() { - lego.Run(s, //运行模块 + lego.Run(service, //运行模块 module, ) }() - time.Sleep(time.Second) + time.Sleep(time.Second * 3) defer os.Exit(m.Run()) } func Test_Log(t *testing.T) { - items, err := module.db_comp.Pack_QueryUserPack("liwei1dao") - log.Debugf("item:%v err:%v", items, err) + data, _ := ptypes.MarshalAny(&pb.GetlistReq{}) + s_gateComp.ReceiveMsg(context.Background(), &pb.AgentMessage{Method: "pack.getlist", Message: data}, &pb.RPCMessageReply{}) + // items, err := module.db_comp.Pack_QueryUserPack("liwei1dao") + // log.Debugf("item:%v err:%v", items, err) } diff --git a/services/comp_gateroute.go b/services/comp_gateroute.go index bc6bf11a8..1d61b7602 100644 --- a/services/comp_gateroute.go +++ b/services/comp_gateroute.go @@ -117,7 +117,7 @@ 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) this.mrlock.RLock() msghandle, ok := this.msghandles[args.Method] - msgcheck := this.msghandles[args.Method] + msgcheck := this.msgcheck[args.Method] this.mrlock.RUnlock() if ok { session := comm.NewUserSession(this.service, args.Ip, args.UserSessionId, args.GatewayServiceId, args.UserId) @@ -126,15 +126,15 @@ func (this *SComp_GateRouteComp) ReceiveMsg(ctx context.Context, args *pb.AgentM log.Errorf("UserMessage:%s Unmarshal err:%v", args.Method, err) return err } - returnValues := msgcheck.fn.Func.Call([]reflect.Value{msgcheck.rcvr, reflect.ValueOf(ctx), reflect.ValueOf(session), reflect.ValueOf(msg)}) + 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].Int() if pb.ErrorCode(code) != pb.ErrorCode_Success { log.Errorf("HandleUserMsg:%s msg:%v code:%d", args.Method, msg, code) return nil } - // result := .Interface().(map[string]interface{}) - msghandle.fn.Func.Call([]reflect.Value{msghandle.rcvr, reflect.ValueOf(session), reflect.ValueOf(returnValues[0]), reflect.ValueOf(msg)}) + result := returnValues[0].Interface().(map[string]interface{}) + msghandle.fn.Func.Call([]reflect.Value{msghandle.rcvr, reflect.ValueOf(session), reflect.ValueOf(result), reflect.ValueOf(msg)}) } else { reply.Code = pb.ErrorCode_ReqParameterError // reply.Msg = pb.GetErrorCodeMsg(pb.ErrorCode_ReqParameterError)