asp.net core consul

服务注册与发现,服务健康检查

https://www.consul.io/downloads

下载

就一个consul.exe文件。

1.安装

三种角色

-dev

consul agent -dev -client=0.0.0.0

-client=0.0.0.0代理谁可以访问,目前的意思是任意客户端都可以访问。

 输入http://localhost:8500/

 

注册到consul

            ConsulClient consulClient = new ConsulClient(c =>
            {
                //注册中心的IP地址
                c.Address = new Uri("http://localhost:8500/");
                //注册中心的名称
                c.Datacenter = "dc1";
            });
            consulClient.Agent.ServiceRegister(new AgentServiceRegistration()
            {
                //每各应用唯一标识
                ID = "service" + Guid.NewGuid(),
                //多个相同应用共同的名字
                Name = "ceshi",
                //
                Address = "localhost",
                //
                Port = 5000,
                //
                Check = new AgentServiceCheck()
                {
                    //12秒检测一次
                    Interval = TimeSpan.FromSeconds(12),
                    //
                    HTTP = $"http://localhost:5000/health",
                    //等待响应的时间,如果5秒内没响应认为该移除
                    Timeout= TimeSpan.FromSeconds(12),
                    //认为挂掉以后,12秒后移除
                    DeregisterCriticalServiceAfter = TimeSpan.FromSeconds(12),
                }
            });

成功后

从consul获取

 

 

 

 

 

-client

-server

 

posted @ 2021-09-05 12:32  富坚老贼  阅读(31)  评论(0编辑  收藏  举报