![]() |
VOOZH | about |
dotnet add package SyZero.Consul --version 1.1.9
NuGet\Install-Package SyZero.Consul -Version 1.1.9
<PackageReference Include="SyZero.Consul" Version="1.1.9" />
<PackageVersion Include="SyZero.Consul" Version="1.1.9" />Directory.Packages.props
<PackageReference Include="SyZero.Consul" />Project file
paket add SyZero.Consul --version 1.1.9
#r "nuget: SyZero.Consul, 1.1.9"
#:package SyZero.Consul@1.1.9
#addin nuget:?package=SyZero.Consul&version=1.1.9Install as a Cake Addin
#tool nuget:?package=SyZero.Consul&version=1.1.9Install as a Cake Tool
SyZero 框架的 Consul 服务注册与发现模块。
dotnet add package SyZero.Consul
{
"Consul": {
"ConsulAddress": "http://localhost:8500",
"Token": "",
"ServiceName": "my-service",
"ServiceAddress": "localhost",
"ServicePort": 5000,
"HealthCheckUrl": "/health"
}
}
// Program.cs
var builder = WebApplication.CreateBuilder(args);
// 添加SyZero
builder.AddSyZero();
// 注册服务方式1 - 使用配置文件
builder.Services.AddConsul();
// 注册服务方式2 - 使用委托配置
builder.Services.AddConsul(options =>
{
options.ConsulAddress = "http://localhost:8500";
options.ServiceName = "my-service";
options.ServicePort = 5000;
});
// 注册服务方式3 - 指定配置节
builder.Services.AddConsul(builder.Configuration, "Consul");
var app = builder.Build();
// 使用SyZero
app.UseSyZero();
app.Run();
public class MyService
{
private readonly IServiceManagement _serviceManagement;
public MyService(IServiceManagement serviceManagement)
{
_serviceManagement = serviceManagement;
}
public async Task<string> GetServiceUrlAsync(string serviceName)
{
var service = await _serviceManagement.GetServiceAsync(serviceName);
return $"{service.Address}:{service.Port}";
}
}
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
ConsulAddress |
string |
"" |
Consul 服务地址 |
Token |
string |
"" |
Consul ACL Token |
ServiceName |
string |
"" |
服务名称 |
ServiceAddress |
string |
"" |
服务地址 |
ServicePort |
int |
0 |
服务端口 |
HealthCheckUrl |
string |
"/health" |
健康检查地址 |
| 方法 | 说明 |
|---|---|
GetServiceAsync(serviceName) |
获取服务实例 |
GetServicesAsync(serviceName) |
获取所有服务实例 |
RegisterAsync() |
注册服务 |
DeregisterAsync() |
注销服务 |
所有方法都有对应的异步版本(带
Async后缀)
builder.Configuration.AddConsulConfiguration(options =>
{
options.Address = "http://localhost:8500";
options.Key = "config/my-service";
});
app.MapHealthChecks("/health");
MIT License - 详见
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 netstandard2.1 is compatible. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.9 | 104 | 4/19/2026 |
| 1.1.9-dev.2 | 55 | 4/19/2026 |
| 1.1.9-dev.1 | 54 | 4/17/2026 |
| 1.1.8 | 104 | 4/17/2026 |
| 1.1.6 | 100 | 4/17/2026 |
| 1.1.6-dev.1 | 55 | 4/17/2026 |
| 1.1.5 | 115 | 4/13/2026 |
| 1.1.5-dev.3 | 59 | 4/13/2026 |
| 1.1.5-dev.2 | 71 | 2/11/2026 |
| 1.1.5-dev.1 | 68 | 1/29/2026 |
| 1.1.4 | 143 | 1/2/2026 |
| 1.1.4-dev.2 | 78 | 1/2/2026 |
| 1.1.4-dev.1 | 86 | 12/30/2025 |
| 1.1.3 | 148 | 12/30/2025 |
| 1.1.3-dev.6 | 76 | 12/30/2025 |
| 1.1.3-dev.3 | 149 | 1/19/2024 |
| 1.1.3-dev.2 | 214 | 11/3/2023 |
| 1.1.3-dev.1 | 264 | 3/21/2023 |
| 1.1.2 | 417 | 3/15/2023 |
| 1.0.0 | 104 | 4/17/2026 |