<develop>:(ShopERP 端)<无> ApiGateWay 参数 Datacenter 优化。

parent be311504
...@@ -27,18 +27,22 @@ namespace ShopERP.Ocelot.ApiGateWay.Infrastructure ...@@ -27,18 +27,22 @@ namespace ShopERP.Ocelot.ApiGateWay.Infrastructure
using (ConsulClient client = new ConsulClient(c => using (ConsulClient client = new ConsulClient(c =>
{ {
c.Address = new Uri(_configuration["Consul:consulAddress"]); c.Address = new Uri(_configuration["Consul:consulAddress"]);
c.Datacenter = "apiService"; c.Datacenter = "dc1";
})) }))
{ {
//根据服务名获取健康的服务 //根据服务名获取健康的服务
var queryResult = client.Health.Service(serviceName, string.Empty, true); var queryResult = client.Health.Service(serviceName, string.Empty, true);
var len = queryResult.Result.Response.Length;
//平均策略-多个负载中随机获取一个 if (queryResult != null && queryResult.Result != null)
var node = queryResult.Result.Response[new Random().Next(len)]; {
var len = queryResult.Result.Response.Length;
domain = $"http://{node.Service.Address}:{node.Service.Port}"; //平均策略-多个负载中随机获取一个
var node = queryResult.Result.Response[new Random().Next(len)];
domain = $"http://{node.Service.Address}:{node.Service.Port}";
}
} }
return domain; return domain;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment