Skip to content

Fast.Consul 公开 API

目标 net8.0;net9.0;net10.0。本页为语法声明与 XML 注释参考,运行示例和边界见模块用法

源码提交:43554c07f6c216f80b509bd535c0a5b66ae7f2e8。维护流程:scripts/export-dotnet-api.ps1;普通站点构建直接消费此文件。

Fast.Consul.ConsulServiceCollectionExtensions

源码 · 目标:net8.0、net9.0、net10.0

csharp
public static class ConsulServiceCollectionExtensions

Consul 服务注册扩展

Fast.Consul.ConsulServiceCollectionExtensions.AddFastConsul

源码 · 目标:net8.0、net9.0、net10.0

csharp
public static IServiceCollection AddFastConsul(this IServiceCollection services, IConfiguration configuration,
        string section = "ConsulSettings")

注册 Consul 服务发现、健康检查和键值服务

  • 参数 services:服务注册集合
  • 参数 configuration:应用配置
  • 参数 section:配置节点名称
  • 返回:返回当前服务注册集合,便于链式调用

Fast.Consul.IKeyValueService

源码 · 目标:net8.0、net9.0、net10.0

csharp
public interface IKeyValueService

Key/Value 服务

Fast.Consul.IKeyValueService.GetKeyValue

源码 · 目标:net8.0、net9.0、net10.0

csharp
Task<T> GetKeyValue<T>(string settingPath, string dcName);

读取 Consul 配置

  • 异常 ArgumentExceptionsettingPathdcName 为空
  • 异常 KeyNotFoundException:Consul 中不存在指定路径的配置
  • 异常 FormatException:Consul 返回的配置值不是有效的 Base64 文本
  • 异常 System.Text.Json.JsonException:配置内容无法反序列化为 T
  • 参数 settingPath:Consul 中保存配置的键路径
  • 参数 dcName:Consul 数据中心名称
  • 类型参数 T:配置值反序列化后的类型
  • 返回:表示异步读取 Consul 配置的任务,任务结果为读取到的 Consul 配置

Fast.Consul.IKeyValueService.GetKeyValue

源码 · 目标:net8.0、net9.0、net10.0

csharp
Task<string> GetKeyValue(string settingPath, string dcName);

读取 Consul 配置

  • 异常 ArgumentExceptionsettingPathdcName 为空
  • 异常 KeyNotFoundException:Consul 中不存在指定路径的配置
  • 异常 FormatException:Consul 返回的配置值不是有效的 Base64 文本
  • 参数 settingPath:Consul 中保存配置的键路径
  • 参数 dcName:Consul 数据中心名称
  • 返回:表示异步读取 Consul 配置的任务,任务结果为读取到的 Consul 配置

Fast.Consul.IKeyValueService.EditKeyValue

源码 · 目标:net8.0、net9.0、net10.0

csharp
Task<bool> EditKeyValue(string settingPath, string dcName, string data);

编辑 Consul 配置

  • 异常 ArgumentExceptionsettingPathdcName 为空
  • 参数 settingPath:Consul 中保存配置的键路径
  • 参数 dcName:Consul 数据中心名称
  • 参数 data:要写入 Consul 的配置文本
  • 返回:Consul 确认写入成功时返回 true;否则返回 false

Fast.Consul.KeyValueService

源码 · 目标:net8.0、net9.0、net10.0

csharp
public class KeyValueService : IKeyValueService

说明继承自接口或基类,需结合对应声明阅读。

Fast.Consul.KeyValueService.GetKeyValue

源码 · 目标:net8.0、net9.0、net10.0

csharp
public async Task<T> GetKeyValue<T>(string settingPath, string dcName)

说明继承自接口或基类,需结合对应声明阅读。

Fast.Consul.KeyValueService.GetKeyValue

源码 · 目标:net8.0、net9.0、net10.0

csharp
public async Task<string> GetKeyValue(string settingPath, string dcName)

说明继承自接口或基类,需结合对应声明阅读。

Fast.Consul.KeyValueService.EditKeyValue

源码 · 目标:net8.0、net9.0、net10.0

csharp
public async Task<bool> EditKeyValue(string settingPath, string dcName, string data)

说明继承自接口或基类,需结合对应声明阅读。

Fast.Consul.ConsulSettingsOptions

源码 · 目标:net8.0、net9.0、net10.0

csharp
public sealed class ConsulSettingsOptions : IPostConfigure

Consul 配置选项

Fast.Consul.ConsulSettingsOptions.Enable

源码 · 目标:net8.0、net9.0、net10.0

csharp
[Required]
    public bool? Enable { get; set; }

Consul 是否启用

Fast.Consul.ConsulSettingsOptions.Address

源码 · 目标:net8.0、net9.0、net10.0

csharp
[Required]
    public string Address { get; set; }

Consul 客户端地址

Fast.Consul.ConsulSettingsOptions.ServiceAddress

源码 · 目标:net8.0、net9.0、net10.0

csharp
public string ServiceAddress { get; set; }

对外注册的服务地址;为空时使用服务器实际监听地址

说明:容器或反向代理场景应显式配置可被 Consul 访问的绝对地址

Fast.Consul.ConsulSettingsOptions.HealthCheck

源码 · 目标:net8.0、net9.0、net10.0

csharp
[Required]
    public string HealthCheck { get; set; }

Consul 健康检查地址

Fast.Consul.ConsulSettingsOptions.DeregisterCriticalServiceAfter

源码 · 目标:net8.0、net9.0、net10.0

csharp
public int? DeregisterCriticalServiceAfter { get; set; }

Consul 服务启动后多久注册,单位为秒

Fast.Consul.ConsulSettingsOptions.HealthCheckInterval

源码 · 目标:net8.0、net9.0、net10.0

csharp
public int? HealthCheckInterval { get; set; }

Consul 健康检查时间间隔,单位为秒

Fast.Consul.ConsulSettingsOptions.HealthCheckTimeout

源码 · 目标:net8.0、net9.0、net10.0

csharp
public int? HealthCheckTimeout { get; set; }

Consul 健康检查超时时间,单位为秒

Fast.Consul.ConsulSettingsOptions.PostConfigure

源码 · 目标:net8.0、net9.0、net10.0

csharp
public void PostConfigure()

说明继承自接口或基类,需结合对应声明阅读。