• consul安装使用


    consul安装使用(consul 0.7.2.6)

    1.安装consul
    2.代码引用consul
    3. consulConfig 读取配置文件:ip,port,servicename
    4.//向Consul注册服务
    //心跳检测设置
    var httpCheck = new AgentServiceCheck()
    {
    DeregisterCriticalServiceAfter = TimeSpan.FromMinutes(3), //心跳检测失败多久后注销
    Interval = TimeSpan.FromSeconds(10), //间隔多久心跳检测一次
    HTTP = $"http://{localIP}:{localPort}/Vxxxx/Health/Check", //心跳检查地址,本服务提供的地址
    Timeout = TimeSpan.FromSeconds(10) //心跳检测超时时间
    };

    //服务名
    var serviceName = consulConfig.ServiceName;

    //注册信息
    var registration = new AgentServiceRegistration()
    {
    ID = $"{localIP}:{localPort}", //服务ID,唯一
    Name = serviceName, //服务名(如果服务搭集群,它们的服务名应该是一样的,但是ID不一样)
    Address = $"{localIP}", //服务地址
    Port = localPort, //服务端口
    Tags = new string[] { }, //服务标签,一般可以用来设置权重等本地服务特有信息
    Checks = new[] { httpCheck }, //心跳检测设置
    };

    //向Consul注册服务
    consulClient.Agent.ServiceRegister(registration).Wait();

    //关闭程序后注销到Consul
    appLifetime.ApplicationStopped.Register(() =>
    {
    consulClient.Agent.ServiceDeregister(registration.ID).Wait();
    });

  • 相关阅读:
    tomcat---基本知识点解读;配置文件详解
    nginx常用配置参数介绍-upstream
    nginx配置文件-详解
    nginx简单介绍
    GCC编译已经引入math.h文件提示cos,sin等函数未定义
    进程与进程间通信(3)
    进程与进程间通信(1)
    进程与进程间通信(2)
    primer_c++_迭代器
    primer_C++_3.5 数组
  • 原文地址:https://www.cnblogs.com/csj007523/p/13857349.html
Copyright © 2020-2023  润新知