在C#中向领事注册健康检查

时间:2019-10-13 10:20:40

标签: c# consul

使用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.");
}

1 个答案:

答案 0 :(得分:0)

您可以在注册时添加支票

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 的节点部分找到您的支票。