NetPro.ConsulClient 6.0.15

.NET 6.0 .NET Core 3.1
NuGet\Install-Package NetPro.ConsulClient -Version 6.0.15
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.
dotnet add package NetPro.ConsulClient --version 6.0.15
<PackageReference Include="NetPro.ConsulClient" Version="6.0.15" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetPro.ConsulClient --version 6.0.15
#r "nuget: NetPro.ConsulClient, 6.0.15"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. 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.15

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

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 Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp3.1
Compatible target framework(s)
Additional computed target framework(s)
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.15 57 7/19/2022
6.0.14 70 7/10/2022
6.0.13 55 6/15/2022
6.0.12 49 6/15/2022
6.0.11 50 6/15/2022
6.0.10 64 6/11/2022
6.0.9 67 6/8/2022
6.0.8 59 5/26/2022
6.0.8-beta.3 190 5/24/2022
6.0.8-beta.2 52 5/24/2022
6.0.7 67 5/18/2022
6.0.6 64 4/28/2022
6.0.5 58 3/30/2022
6.0.5-beta.20 62 4/27/2022
6.0.5-beta.19 59 4/25/2022
6.0.5-beta.18 56 4/22/2022
6.0.5-beta.17 63 4/16/2022
6.0.5-beta.16 127 4/8/2022
6.0.5-beta.15 61 4/8/2022
6.0.5-beta.14 67 4/7/2022
6.0.5-beta.13 65 4/7/2022
6.0.5-beta.12 65 4/6/2022
6.0.5-beta.11 64 4/6/2022
6.0.5-beta.10 56 3/31/2022
6.0.5-beta.9 120 3/26/2022
6.0.5-beta.8 73 3/22/2022
6.0.5-beta.7 70 3/21/2022
6.0.5-beta.6 65 3/14/2022
6.0.5-beta.5 73 3/2/2022
6.0.5-beta.4 62 2/22/2022
6.0.5-beta.3 66 2/18/2022
6.0.5-beta.2 60 2/18/2022
6.0.5-beta.1 65 2/16/2022
6.0.4 110 2/10/2022
6.0.3 103 2/9/2022
6.0.3-beta.9 64 2/10/2022
6.0.3-beta.7 89 1/27/2022
6.0.3-beta.6 78 1/19/2022
6.0.3-beta.5 89 1/17/2022
6.0.3-beta.4 87 1/16/2022
6.0.3-beta.3 86 1/14/2022
6.0.3-beta.2 76 1/13/2022
6.0.3-beta.1 92 1/11/2022
6.0.2 142 1/6/2022
1.0.0 202 12/20/2021