上传rpcx 负载均衡代码

This commit is contained in:
liwei1dao 2023-09-06 18:26:53 +08:00
parent 22283a26ff
commit 146eb77f4e
2 changed files with 8 additions and 8 deletions

View File

@ -333,16 +333,16 @@ func (this *Client) getclient(ctx *context.Context, clusterTag string, servicePa
if d, err = client.NewConsulDiscovery(clusterTag, spath[0], this.options.ConsulServers, nil); err != nil {
return
}
c = client.NewBidirectionalXClient(spath[0], client.Failfast, client.RandomSelect, d, client.DefaultOption, this.msgChan)
c = client.NewBidirectionalXClient(spath[0], client.Failfast, client.RoundRobin, d, client.DefaultOption, this.msgChan)
cluster.Mu.Lock()
cluster.clients[spath[0]] = c
cluster.Mu.Unlock()
c.GetPlugins().Add(this)
if this.options.RpcxStartType == RpcxStartByClient && this.options.AutoConnect {
// if this.options.RpcxStartType == RpcxStartByClient && this.options.AutoConnect {
c.SetSelector(newSelector(this.options.Log, clusterTag, this.UpdateServer))
} else {
c.SetSelector(newSelector(this.options.Log, clusterTag, nil))
}
// } else {
// c.SetSelector(newSelector(this.options.Log, clusterTag, nil))
// }
}
*ctx = context.WithValue(*ctx, share.ReqMetaDataKey, map[string]string{

View File

@ -103,11 +103,11 @@ func (this *Selector) UpdateServer(servers map[string]string) {
continue
} else {
ss[node.ServiceId] = node
if ssts, ok := sst[node.ServiceType]; !ok {
if _, ok := sst[node.ServiceType]; !ok {
sst[node.ServiceType] = make([]*ServiceNode, 0)
sst[node.ServiceType] = append(sst[node.ServiceType], node)
} else {
ssts = append(ssts, node)
sst[node.ServiceType] = append(sst[node.ServiceType], node)
}
}