NetPro.ConsulClient 6.0.16

dotnet add package NetPro.ConsulClient --version 6.0.16                
NuGet\Install-Package NetPro.ConsulClient -Version 6.0.16                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NetPro.ConsulClient" Version="6.0.16" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetPro.ConsulClient --version 6.0.16                
#r "nuget: NetPro.ConsulClient, 6.0.16"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install NetPro.ConsulClient as a Cake Addin
#addin nuget:?package=NetPro.ConsulClient&version=6.0.16

// Install NetPro.ConsulClient as a Cake Tool
#tool nuget:?package=NetPro.ConsulClient&version=6.0.16                

NetPro.Proxy使用

NuGet

Consul 客户端

使用

  • 健康检查默认以TTL模式,10秒检查

  • 如在容器中使用,会自动发现容器ip与程序分配的默认端口。

  • 如需要指定ip地址需配置如下LANIP和PORT环境变量,默认遍历本机所有网卡地址的第一个与分配给程序的默认端口,示例如下: 宿主机IP地址 LANIP=192.168.1.1 端口号 PORT=5000

appsetting.json
  • 增加以下配置节点
  "ConsulOption": {
    "Enabled": false, //是否开启,不配置默认开启
    "ServiceName": "xxx.api", //可留空;留空默认以入口程序名作为servicename
    "EndPoint": "http://localhost:8500",
    "WaitTime": null,
    "Tags": [ "HUHU" ], //可留空
    "Datacenter": null, //可留空
    "Token": null //可留空
  }

如果基于NetPro.WebApi的项目,只需要以上配置即可,如不是基于NetPro.WebApi的项目,需手动按一下初始化组件

启用服务
public void ConfigureServices(IServiceCollection services, IConfiguration configuration = null)
        {
            services.AddConsul(configuration);
        }

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseConsuClient();
        }
ublic class ConsulDemoController : ControllerBase
    {

        private readonly ILogger<TimeZoneDemoController> _logger;
        private readonly IConsulClient _consulClient;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="consulClient"></param>
        public TimeZoneDemoController(ILogger<TimeZoneDemoController> logger,
        IConsulClient consulClient)
        {
            _logger = logger;
            _consulClient=consulClient;
        }

        /// <summary>
        /// consul发现服务
        /// </summary>
        [HttpGet("DiscoveryServices")]
        [ProducesResponseType(200, Type = typeof(ResponseResult))]
        public async Task<IActionResult> DiscoveryServices(string serviceName = "XXX.API")
        {
            //以下几种方式都可拿到注册的服务地址
            var result = await _consulClient.Agent.DiscoveryAsync();
            var result1 = await _consulClient.Catalog.DiscoveryAsync(serviceName);
            var result2 = await _consulClient.DiscoveryAsync(serviceName);
            return Ok(new { result, result1, result2 });
        }
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on NetPro.ConsulClient:

Repository Stars
LeonKou/NetPro
🌈An enhanced version with clean architecture of asp.netcore,efficiently manage startup,Support for netcore3.1/6.0
Version Downloads Last updated
6.0.16 147 7/24/2023
6.0.15 147 7/19/2022
6.0.14 151 7/10/2022
6.0.13 138 6/15/2022
6.0.12 127 6/15/2022
6.0.11 136 6/15/2022
6.0.10 149 6/11/2022
6.0.9 142 6/8/2022
6.0.8 135 5/26/2022
6.0.8-beta.3 510 5/24/2022
6.0.8-beta.2 116 5/24/2022
6.0.7 146 5/18/2022
6.0.6 143 4/28/2022
6.0.5 148 3/30/2022
6.0.5-beta.20 131 4/27/2022
6.0.5-beta.19 124 4/25/2022
6.0.5-beta.18 121 4/22/2022
6.0.5-beta.17 131 4/16/2022
6.0.5-beta.16 197 4/8/2022
6.0.5-beta.15 129 4/8/2022
6.0.5-beta.14 143 4/7/2022
6.0.5-beta.13 130 4/7/2022
6.0.5-beta.12 129 4/6/2022
6.0.5-beta.11 126 4/6/2022
6.0.5-beta.10 131 3/31/2022
6.0.5-beta.9 191 3/26/2022
6.0.5-beta.8 147 3/22/2022
6.0.5-beta.7 147 3/21/2022
6.0.5-beta.6 140 3/14/2022
6.0.5-beta.5 139 3/2/2022
6.0.5-beta.4 134 2/22/2022
6.0.5-beta.3 135 2/18/2022
6.0.5-beta.2 125 2/18/2022
6.0.5-beta.1 136 2/16/2022
6.0.4 469 2/10/2022
6.0.3 449 2/9/2022
6.0.3-beta.9 133 2/10/2022
6.0.3-beta.7 156 1/27/2022
6.0.3-beta.6 139 1/19/2022
6.0.3-beta.5 155 1/17/2022
6.0.3-beta.4 151 1/16/2022
6.0.3-beta.3 148 1/14/2022
6.0.3-beta.2 140 1/13/2022
6.0.3-beta.1 174 1/11/2022
6.0.2 328 1/6/2022
1.0.0 379 12/20/2021