在 C# 中使用 consul 注册健康检查
Registering a health check with consul in C#
使用 dotnet 客户端进行咨询,关于 API 的文档不多,但遵循了 Unit Tests。
如何指定持续检查此已注册微服务的健康状态的检查设置?
using (var consul = new ConsulClient(configuration => configuration.Address = new Uri("http://localhost:8500")))
{
var registration = new AgentServiceRegistration
{
ID = "customer",
Name = "customer",
Address = Dns.GetHostName(),
Port = 80
};
consul.Agent.ServiceDeregister(registration.ID).Wait();
consul.Agent.ServiceRegister(registration).Wait();
Console.WriteLine("Registered with Consul.");
}
您可以在注册时添加支票
using (var consul = new ConsulClient(configuration => configuration.Address = new Uri("http://localhost:8500")))
{
var registration = new AgentServiceRegistration
{
ID = "customer",
Name = "customer",
Address = Dns.GetHostName(),
Port = 80
//at your check code here
Check = new AgentServiceCheck()
{
HTTP = "http://yourUrl.com",
Interval = TimeSpan.FromMinutes(5),
Timeout = TimeSpan.FromMinutes(1),
},
};
consul.Agent.ServiceDeregister(registration.ID).Wait();
consul.Agent.ServiceRegister(registration).Wait();
Console.WriteLine("Registered with Consul.");
}
现在您可以在 consul.ui 的节点部分找到您的支票。
使用 dotnet 客户端进行咨询,关于 API 的文档不多,但遵循了 Unit Tests。
如何指定持续检查此已注册微服务的健康状态的检查设置?
using (var consul = new ConsulClient(configuration => configuration.Address = new Uri("http://localhost:8500")))
{
var registration = new AgentServiceRegistration
{
ID = "customer",
Name = "customer",
Address = Dns.GetHostName(),
Port = 80
};
consul.Agent.ServiceDeregister(registration.ID).Wait();
consul.Agent.ServiceRegister(registration).Wait();
Console.WriteLine("Registered with Consul.");
}
您可以在注册时添加支票
using (var consul = new ConsulClient(configuration => configuration.Address = new Uri("http://localhost:8500")))
{
var registration = new AgentServiceRegistration
{
ID = "customer",
Name = "customer",
Address = Dns.GetHostName(),
Port = 80
//at your check code here
Check = new AgentServiceCheck()
{
HTTP = "http://yourUrl.com",
Interval = TimeSpan.FromMinutes(5),
Timeout = TimeSpan.FromMinutes(1),
},
};
consul.Agent.ServiceDeregister(registration.ID).Wait();
consul.Agent.ServiceRegister(registration).Wait();
Console.WriteLine("Registered with Consul.");
}
现在您可以在 consul.ui 的节点部分找到您的支票。