优化聊天消息广播异常问题

This commit is contained in:
liwei1dao 2022-11-10 20:05:35 +08:00
parent dc30119e55
commit 5eb2783750
4 changed files with 84 additions and 76 deletions

View File

@ -228,6 +228,7 @@ func (this *Client) ClusterBroadcast(ctx context.Context, servicePath string, se
}
this.clusterMu.RUnlock()
l := len(clients)
if l > 0 {
done := make(chan error, l)
for _, v := range clients {
go func(c client.XClient) {
@ -249,6 +250,9 @@ check:
}
}
timeout.Stop()
} else {
err = errors.New("on found any service")
}
return
}

View File

@ -127,8 +127,7 @@ func (this *RPCX) AcrossClusterGo(ctx context.Context, clusterTag string, servic
//全集群广播
func (this *RPCX) ClusterBroadcast(ctx context.Context, servicePath string, serviceMethod string, args interface{}, reply interface{}) (err error) {
err = this.client.ClusterBroadcast(ctx, servicePath, serviceMethod, args, reply)
err = this.service.ClusterBroadcast(ctx, servicePath, serviceMethod, args, reply)
if err != nil && strings.Contains(err.Error(), "on found") {
return this.client.ClusterBroadcast(ctx, servicePath, serviceMethod, args, reply)
}

View File

@ -496,6 +496,7 @@ func (this *Service) clusterbroadcast(ctx context.Context, servicePath string, s
}
l := len(addrs)
if l > 0 {
done := make(chan error, l)
for v, _ := range addrs {
go func(addr string) {
@ -555,7 +556,11 @@ check:
}
}
timeout.Stop()
return err
} else {
err = errors.New("on found any service")
}
return
}
//发送远程调用请求

View File

@ -82,7 +82,7 @@ func (this *Chat) OnInstallComp() {
//Event------------------------------------------------------------------------------------------------------------
func (this *Chat) EventUserOffline(session comm.IUserSession) {
if err := this.modelChat.removeCrossChannelMember(session); err != nil {
this.Debug("EventUserOffline:", log.Field{"uid", session.GetUserId()}, log.Field{"err", err})
this.Debug("EventUserOffline:", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "err", Value: err.Error()})
}
}
@ -151,7 +151,7 @@ func (this *Chat) SendWorldChat(msg *pb.DBChat) (code pb.ErrorCode) {
} else {
if _, err = this.service.AcrossClusterRpcGo(
context.Background(),
msg.Stag,
this.GetCrossTag(),
comm.Service_Worker,
string(comm.Rpc_ModuleChatPushChat),
msg,
@ -182,7 +182,7 @@ func (this *Chat) SendUnionChat(msg *pb.DBChat) (code pb.ErrorCode) {
} else {
if _, err = this.service.AcrossClusterRpcGo(
context.Background(),
msg.Stag,
this.GetCrossTag(),
comm.Service_Worker,
string(comm.Rpc_ModuleChatPushChat),
msg,
@ -257,7 +257,7 @@ func (this *Chat) SendSysChatToWorld(ctype comm.ChatSystemType, appenddata inter
} else {
if _, err = this.service.AcrossClusterRpcGo(
context.Background(),
msg.Stag,
this.GetCrossTag(),
comm.Service_Worker,
string(comm.Rpc_ModuleChatPushChat),
msg,