BorgNet.Consul 1.0.0

dotnet add package BorgNet.Consul --version 1.0.0
NuGet\Install-Package BorgNet.Consul -Version 1.0.0
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="BorgNet.Consul" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BorgNet.Consul --version 1.0.0
#r "nuget: BorgNet.Consul, 1.0.0"
#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 BorgNet.Consul as a Cake Addin
#addin nuget:?package=BorgNet.Consul&version=1.0.0

// Install BorgNet.Consul as a Cake Tool
#tool nuget:?package=BorgNet.Consul&version=1.0.0

Consul 客户端

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

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

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

使用 appsetting.json "ConsulOptions": { /// 是否开启,默认开启 "Enabled": true, /// 服务名称,默认当前运行程序集名称 "ServiceName": "BorgNet.AspNetCore3", //服务地址 "ServiceHost": "http://localhost:65143", /// consul服务所在地址 "EndPoint": "http://localhost:8500",

"Tags": [ "HUHU" ], //可留空 
"Datacenter": "", /// 数据中心,默认空

"Token": "" /// Token默认空

} 启用服务 如下:

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

public void ConfigureServices(IServiceCollection services,IConfiguration Configuration) { services.AddNetConsul(configuration); }

使用说明 public class ConsulDemoController : ControllerBase {

    private readonly IConsulClient _consulClient;
    /// <summary>
    /// 
    /// </summary>
    /// <param name="consulClient"></param>
    public ConsulDemoController(IConsulClient consulClient)
    {
        _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 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. 
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

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 174 1/29/2023