1.本地开启多个实例:
Dotnet *****.dll --urls="http://*:9115" --ip="127.0.0.1" --port=9115
Dotnet *****.dll --urls="http://*:9116" --ip="127.0.0.1" --port=9116
Dotnet *****.dll --urls="http://*:9117" --ip="127.0.0.1" --port=9117
2.开启Consul服务
Consul.exe agent -dev
3.Consul服务端注册
ConsulClient client = new ConsulClient(c =>
{
c.Address = new Uri("http://localhost:8500/");
c.Datacenter = "dc1";
});
string ip = configuration["ip"];
int port = int.Parse(configuration["port"]);
client.Agent.ServiceRegister(new AgentServiceRegistration()
{
ID = "Test" + Guid.NewGuid(),
Name = "Test",
Address = ip,
Port = port,
});
4.客户端服务法发现
ConsulClient client = new ConsulClient(c =>
{
c.Address = new Uri("http://localhost:8500/");
c.Datacenter = "dc1";
});
var response = client.Agent.Services().Result.Response;