扩展基础模块内置接口
This commit is contained in:
parent
ba8e0f92c7
commit
7550002f7a
@ -1,6 +1,8 @@
|
||||
package modules
|
||||
|
||||
import (
|
||||
"go_dreamfactory/pb"
|
||||
|
||||
"github.com/liwei1dao/lego/core"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
@ -8,6 +10,7 @@ import (
|
||||
type (
|
||||
IModule interface {
|
||||
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
|
||||
}
|
||||
|
||||
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{}
|
||||
data, _ := proto.Marshal(msg)
|
||||
if err = this.service.RpcCallById(GatewayServiceId, string(comm.Rpc_GatewayAgentSendMsg), context.Background(), &pb.AgentSendMessageReq{
|
||||
UserSessionId: SessionId,
|
||||
if _, err = this.service.RpcGoById(user.GatewayServiceId, string(comm.Rpc_GatewayAgentSendMsg), context.Background(), &pb.AgentSendMessageReq{
|
||||
UserSessionId: user.SessionId,
|
||||
ServiceMethod: ServiceMethod,
|
||||
Data: data,
|
||||
}, 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
|
||||
}
|
||||
|
||||
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{}
|
||||
data, _ := proto.Marshal(msg)
|
||||
if err = this.service.RpcCallById(GatewayServiceId, string(comm.Rpc_GatewayAgentSendMsg), context.Background(), &pb.AgentSendMessageReq{
|
||||
UserSessionId: SessionId,
|
||||
for k, v := range gateways {
|
||||
if _, err = this.service.RpcGoById(k, string(comm.Rpc_GatewayAgentSendMsg), context.Background(), &pb.BatchMessageReq{
|
||||
UserSessionIds: v,
|
||||
ServiceMethod: ServiceMethod,
|
||||
Data: data,
|
||||
}, reply); err != nil {
|
||||
log.Errorf("SendMsgToAgent%s:[%s] err:%v", SessionId, ServiceMethod, err)
|
||||
log.Errorf("SendMsgToUsers:%s->%s err:%v", k, ServiceMethod, err)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"go_dreamfactory/modules/login"
|
||||
"go_dreamfactory/services"
|
||||
"go_dreamfactory/sys/cache"
|
||||
|
Loading…
Reference in New Issue
Block a user