From e741a243dd825a82410cccb1be8f002af1b59838 Mon Sep 17 00:00:00 2001 From: liangdas <1587790525@qq.com> Date: Tue, 19 Dec 2017 10:47:31 +0800 Subject: [PATCH] =?UTF-8?q?=3D=E4=BC=98=E5=8C=96rpc=E9=80=9A=E4=BF=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/app.go | 24 +++++++++++++++--------- gate/base/gate_handler.go | 6 +++--- module/module.go | 1 + utils/redis.go | 2 +- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/app/app.go b/app/app.go index e75494c..cbf5bd9 100644 --- a/app/app.go +++ b/app/app.go @@ -70,6 +70,7 @@ type DefaultApp struct { version string serverList map[string]module.ServerSession settings conf.Config + processId string routes map[string]func(app module.App, Type string, hash string) module.ServerSession defaultRoutes func(app module.App, Type string, hash string) module.ServerSession rpcserializes map[string]module.RPCSerialize @@ -87,7 +88,7 @@ func (app *DefaultApp) Run(debug bool, mods ...module.Module) error { ProcessID := flag.String("pid", "development", "Server ProcessID?") Logdir := flag.String("log", "", "Log file directory?") flag.Parse() //解析输入的参数 - + app.processId=*ProcessID ApplicationDir := "" if *wdPath != "" { _, err := os.Open(*wdPath) @@ -208,13 +209,16 @@ func (app *DefaultApp) OnInit(settings conf.Config) error { if err != nil { continue } - if moduel.Rabbitmq != nil { - //如果远程的rpc存在则创建一个对应的客户端 - client.NewRabbitmqClient(moduel.Rabbitmq) - } - if moduel.Redis != nil { - //如果远程的rpc存在则创建一个对应的客户端 - client.NewRedisClient(moduel.Redis) + if app.GetProcessID()!=moduel.ProcessID{ + //同一个ProcessID下的模块直接通过local channel通信就可以了 + if moduel.Rabbitmq != nil { + //如果远程的rpc存在则创建一个对应的客户端 + client.NewRabbitmqClient(moduel.Rabbitmq) + } + if moduel.Redis != nil { + //如果远程的rpc存在则创建一个对应的客户端 + client.NewRedisClient(moduel.Redis) + } } session := basemodule.NewServerSession(moduel.Id, Type, client) app.serverList[moduel.Id] = session @@ -284,7 +288,9 @@ func (app *DefaultApp) GetRouteServer(filter string, hash string) (s module.Serv func (app *DefaultApp) GetSettings() conf.Config { return app.settings } - +func (app *DefaultApp) GetProcessID() string { + return app.processId +} func (app *DefaultApp) RpcInvoke(module module.RPCModule, moduleType string, _func string, params ...interface{}) (result interface{}, err string) { server, e := app.GetRouteServer(moduleType, module.GetServerId()) if e != nil { diff --git a/gate/base/gate_handler.go b/gate/base/gate_handler.go index a541d67..9572ed1 100644 --- a/gate/base/gate_handler.go +++ b/gate/base/gate_handler.go @@ -164,7 +164,7 @@ func (h *handler) Push(Sessionid string, Settings map[string]string) (result gat if h.gate.GetStorageHandler() != nil && agent.(gate.Agent).GetSession().GetUserid() != "" { err := h.gate.GetStorageHandler().Storage(agent.(gate.Agent).GetSession().GetUserid(), agent.(gate.Agent).GetSession()) if err != nil { - log.Error("gate session storage failure") + log.Warning("gate session storage failure : %s",err.Error()) } } @@ -186,7 +186,7 @@ func (h *handler) Set(Sessionid string, key string, value string) (result gate.S if h.gate.GetStorageHandler() != nil && agent.(gate.Agent).GetSession().GetUserid() != "" { err := h.gate.GetStorageHandler().Storage(agent.(gate.Agent).GetSession().GetUserid(), agent.(gate.Agent).GetSession()) if err != nil { - log.Error("gate session storage failure") + log.Error("gate session storage failure : %s",err.Error()) } } @@ -208,7 +208,7 @@ func (h *handler) Remove(Sessionid string, key string) (result interface{}, err if h.gate.GetStorageHandler() != nil && agent.(gate.Agent).GetSession().GetUserid() != "" { err := h.gate.GetStorageHandler().Storage(agent.(gate.Agent).GetSession().GetUserid(), agent.(gate.Agent).GetSession()) if err != nil { - log.Error("gate session storage failure") + log.Error("gate session storage failure :%s",err.Error()) } } diff --git a/module/module.go b/module/module.go index 31c6f19..5a24ea9 100644 --- a/module/module.go +++ b/module/module.go @@ -83,6 +83,7 @@ type App interface { */ ProtocolMarshal(Result interface{},Error string)(ProtocolMarshal,string) NewProtocolMarshal(data []byte)(ProtocolMarshal) + GetProcessID()string } type Module interface { diff --git a/utils/redis.go b/utils/redis.go index 564207e..4f5f2b4 100644 --- a/utils/redis.go +++ b/utils/redis.go @@ -41,7 +41,7 @@ func (this RedisFactory) GetPool(url string) *redis.Pool { // 最大的空闲连接数,表示即使没有redis连接时依然可以保持N个空闲的连接,而不被清除,随时处于待命状态 MaxIdle: 10, // 最大的激活连接数,表示同时最多有N个连接 ,为0事表示没有限制 - MaxActive: 0, + MaxActive: 100, //最大的空闲连接等待时间,超过此时间后,空闲连接将被关闭 IdleTimeout: 240 * time.Second, // 当链接数达到最大后是否阻塞,如果不的话,达到最大后返回错误