一、下载安装Consul(服务发现)程序
1、官网地址
https://developer.hashicorp.com/consul/install
2、运行服务发现
consul agent -dev
二、服务发现 Consul
1、添加Consul Nuget包
2、新建WebApi,然后注册服务
/// <summary>
/// 自己封装的注册类
/// </summary>
public static class ConsulHelper
{
public static void ConsulRegist(this IConfiguration configuration)
{
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"]);//命令行参数必须传入
int weight = string.IsNullOrWhiteSpace(configuration["weight"]) ? 1 : int.Parse(configuration["weight"]);//命令行参数必须传入
Console.WriteLine($"健康检查地址: http://{
ip}:{
port}/api/Health/Index");
client.Agent.ServiceRegister(new AgentServiceRegistration()
{
ID = "service"