Galosys.Foundation.Consul 26.7.24.1

dotnet add package Galosys.Foundation.Consul --version 26.7.24.1
                    
NuGet\Install-Package Galosys.Foundation.Consul -Version 26.7.24.1
                    
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="Galosys.Foundation.Consul" Version="26.7.24.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Galosys.Foundation.Consul" Version="26.7.24.1" />
                    
Directory.Packages.props
<PackageReference Include="Galosys.Foundation.Consul" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Galosys.Foundation.Consul --version 26.7.24.1
                    
#r "nuget: Galosys.Foundation.Consul, 26.7.24.1"
                    
#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.
#:package Galosys.Foundation.Consul@26.7.24.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Galosys.Foundation.Consul&version=26.7.24.1
                    
Install as a Cake Addin
#tool nuget:?package=Galosys.Foundation.Consul&version=26.7.24.1
                    
Install as a Cake Tool

Galosys.Foundation.Consul

成熟度: 🟡 可用 — 功能完整,测试或文档可能不完善 目标框架:
et8.0\ ·
et10.0\(#if NET10_0\ 条件编译)

基于 Consul 的服务注册、发现与配置管理模块,提供完整的服务治理能力。

功能概述

  • 服务注册: 将应用服务自动注册到 Consul
  • 服务发现: 支持从 Consul 获取可用服务实例
  • 配置管理: 支持从 Consul 读取 JSON 格式配置
  • DNS 集成: 支持 DNS 方案进行服务发现

依赖项

  • Consul
  • Microsoft.Extensions.Options
  • Microsoft.Extensions.ServiceDiscovery
  • Microsoft.Extensions.Configuration.Consul

配置说明

appsettings.json 中配置 Consul 相关参数:

{
  "Consul": {
    "Http": "http://127.0.0.1:8500",
    "DataCenter": "dev",
    "Addresses": "192.168.1.100:8080",
    "Dns": {
      "Host": "localhost",
      "Port": 8600
    },
    "Config": {
      "Prefix": "config",
      "DataKey": "data",
      "Enabled": true,
      "Format": "JSON"
    }
  }
}

配置项说明

配置项 类型 默认值 说明
Http string http://127.0.0.1:8500 Consul HTTP 地址
DataCenter string 环境变量值 数据中心名称
Addresses string - 注册到 Consul 的服务地址
Dns.Host string localhost DNS 主机
Dns.Port int 8600 DNS 端口
Config.Prefix string - 配置键前缀
Config.DataKey string - 配置数据键名
Config.Enabled bool true 是否启用配置
Config.Format string JSON 配置格式

使用方法

1. 服务注册

模块会自动将服务注册到 Consul:

// 自动从环境变量获取服务地址和端口进行注册
// 服务名称自动从环境变量获取 (Env.GetApplicationName())

2. 服务发现

通过 Consul 进行服务发现:

// 使用 HttpClient 直接请求 Consul 注册的服务
// 格式: http://{服务名}.service.consul

3. 配置读取

从 Consul 读取配置:

// 通过 IConfiguration 接口读取 Consul 配置中心的 JSON 配置

4. 健康检查

Consul 自动对注册服务进行健康检查。

注意事项

  • 确保 Consul 服务端正常运行
  • 服务地址需可访问,Consul 需要进行健康检查
  • 配置中心启用时请确保配置键正确
  • 生产环境建议启用 ACL 认证
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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
26.7.24.1 0 7/24/2026
26.7.22.1 38 7/23/2026
26.7.21.1 61 7/21/2026
26.7.20.2 64 7/20/2026
26.7.20.1 62 7/20/2026
26.7.19.3 61 7/19/2026
26.7.19.2 69 7/19/2026
26.7.19.1 63 7/19/2026
26.7.18.2 68 7/18/2026
26.7.18.1 59 7/18/2026
26.7.17.1 71 7/17/2026
26.7.14.1 92 7/14/2026
26.7.13.1 93 7/13/2026
26.7.12.1 84 7/12/2026
26.7.11.1 92 7/11/2026
26.7.10.2 94 7/10/2026
26.7.10.1 94 7/10/2026
26.7.7.2 101 7/7/2026
26.7.7.1 94 7/7/2026
1.0.0 94 7/7/2026
Loading failed