扩展基础模块内置接口
This commit is contained in:
parent
ba8e0f92c7
commit
7550002f7a
@ -1,6 +1,8 @@
|
|||||||
package modules
|
package modules
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"go_dreamfactory/pb"
|
||||||
|
|
||||||
"github.com/liwei1dao/lego/core"
|
"github.com/liwei1dao/lego/core"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
@ -8,6 +10,7 @@ import (
|
|||||||
type (
|
type (
|
||||||
IModule interface {
|
IModule interface {
|
||||||
core.IModule
|
core.IModule
|
||||||
SendMsgToAgent(GatewayServiceId, SessionId, ServiceMethod string, msg proto.Message) (err error)
|
SendMsgToUser(ServiceMethod string, msg proto.Message, user *pb.Cache_UserData) (err error)
|
||||||
|
SendMsgToUsers(ServiceMethod string, msg proto.Message, user ...*pb.Cache_UserData) (err error)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -23,28 +23,42 @@ func (this *ModuleBase) Init(service core.IService, module core.IModule, options
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ModuleBase) SendMsgToAgent(GatewayServiceId, SessionId, ServiceMethod string, msg proto.Message) (err error) {
|
func (this *ModuleBase) SendMsgToUser(ServiceMethod string, msg proto.Message, user *pb.Cache_UserData) (err error) {
|
||||||
reply := &pb.RPCMessageReply{}
|
reply := &pb.RPCMessageReply{}
|
||||||
data, _ := proto.Marshal(msg)
|
data, _ := proto.Marshal(msg)
|
||||||
if err = this.service.RpcCallById(GatewayServiceId, string(comm.Rpc_GatewayAgentSendMsg), context.Background(), &pb.AgentSendMessageReq{
|
if _, err = this.service.RpcGoById(user.GatewayServiceId, string(comm.Rpc_GatewayAgentSendMsg), context.Background(), &pb.AgentSendMessageReq{
|
||||||
UserSessionId: SessionId,
|
UserSessionId: user.SessionId,
|
||||||
ServiceMethod: ServiceMethod,
|
ServiceMethod: ServiceMethod,
|
||||||
Data: data,
|
Data: data,
|
||||||
}, reply); err != nil {
|
}, reply); err != nil {
|
||||||
log.Errorf("SendMsgToAgent%s:[%s] err:%v", SessionId, ServiceMethod, err)
|
log.Errorf("SendMsgToUser%d:%s [%s] err:%v", user.UserData.UserId, user.SessionId, ServiceMethod, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ModuleBase) SendMsgToAgents(GatewayServiceId, SessionId, ServiceMethod string, msg proto.Message) (err error) {
|
func (this *ModuleBase) SendMsgToUsers(ServiceMethod string, msg proto.Message, user ...*pb.Cache_UserData) (err error) {
|
||||||
|
var (
|
||||||
|
gateways map[string][]string = make(map[string][]string)
|
||||||
|
gateway []string
|
||||||
|
ok bool
|
||||||
|
)
|
||||||
|
for _, v := range user {
|
||||||
|
if gateway, ok = gateways[v.GatewayServiceId]; !ok {
|
||||||
|
gateway = make([]string, 0)
|
||||||
|
gateways[v.GatewayServiceId] = gateway
|
||||||
|
}
|
||||||
|
gateway = append(gateway, v.SessionId)
|
||||||
|
}
|
||||||
reply := &pb.RPCMessageReply{}
|
reply := &pb.RPCMessageReply{}
|
||||||
data, _ := proto.Marshal(msg)
|
data, _ := proto.Marshal(msg)
|
||||||
if err = this.service.RpcCallById(GatewayServiceId, string(comm.Rpc_GatewayAgentSendMsg), context.Background(), &pb.AgentSendMessageReq{
|
for k, v := range gateways {
|
||||||
UserSessionId: SessionId,
|
if _, err = this.service.RpcGoById(k, string(comm.Rpc_GatewayAgentSendMsg), context.Background(), &pb.BatchMessageReq{
|
||||||
|
UserSessionIds: v,
|
||||||
ServiceMethod: ServiceMethod,
|
ServiceMethod: ServiceMethod,
|
||||||
Data: data,
|
Data: data,
|
||||||
}, reply); err != nil {
|
}, reply); err != nil {
|
||||||
log.Errorf("SendMsgToAgent%s:[%s] err:%v", SessionId, ServiceMethod, err)
|
log.Errorf("SendMsgToUsers:%s->%s err:%v", k, ServiceMethod, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"go_dreamfactory/modules/login"
|
"go_dreamfactory/modules/login"
|
||||||
"go_dreamfactory/services"
|
"go_dreamfactory/services"
|
||||||
"go_dreamfactory/sys/cache"
|
"go_dreamfactory/sys/cache"
|
||||||
|
Loading…
Reference in New Issue
Block a user