上传rpcx 负载均衡代码
This commit is contained in:
parent
22283a26ff
commit
146eb77f4e
@ -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 {
|
if d, err = client.NewConsulDiscovery(clusterTag, spath[0], this.options.ConsulServers, nil); err != nil {
|
||||||
return
|
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.Mu.Lock()
|
||||||
cluster.clients[spath[0]] = c
|
cluster.clients[spath[0]] = c
|
||||||
cluster.Mu.Unlock()
|
cluster.Mu.Unlock()
|
||||||
c.GetPlugins().Add(this)
|
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))
|
c.SetSelector(newSelector(this.options.Log, clusterTag, this.UpdateServer))
|
||||||
} else {
|
// } else {
|
||||||
c.SetSelector(newSelector(this.options.Log, clusterTag, nil))
|
// c.SetSelector(newSelector(this.options.Log, clusterTag, nil))
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
*ctx = context.WithValue(*ctx, share.ReqMetaDataKey, map[string]string{
|
*ctx = context.WithValue(*ctx, share.ReqMetaDataKey, map[string]string{
|
||||||
|
@ -103,11 +103,11 @@ func (this *Selector) UpdateServer(servers map[string]string) {
|
|||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
ss[node.ServiceId] = node
|
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] = make([]*ServiceNode, 0)
|
||||||
sst[node.ServiceType] = append(sst[node.ServiceType], node)
|
sst[node.ServiceType] = append(sst[node.ServiceType], node)
|
||||||
} else {
|
} else {
|
||||||
ssts = append(ssts, node)
|
sst[node.ServiceType] = append(sst[node.ServiceType], node)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user