SyZero.Nacos 1.1.5-dev.2

This is a prerelease version of SyZero.Nacos.
dotnet add package SyZero.Nacos --version 1.1.5-dev.2
                    
NuGet\Install-Package SyZero.Nacos -Version 1.1.5-dev.2
                    
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="SyZero.Nacos" Version="1.1.5-dev.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SyZero.Nacos" Version="1.1.5-dev.2" />
                    
Directory.Packages.props
<PackageReference Include="SyZero.Nacos" />
                    
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 SyZero.Nacos --version 1.1.5-dev.2
                    
#r "nuget: SyZero.Nacos, 1.1.5-dev.2"
                    
#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 SyZero.Nacos@1.1.5-dev.2
                    
#: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=SyZero.Nacos&version=1.1.5-dev.2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=SyZero.Nacos&version=1.1.5-dev.2&prerelease
                    
Install as a Cake Tool

SyZero.Nacos

SyZero 框架的 Nacos 服务注册与配置中心模块。

📦 安装

dotnet add package SyZero.Nacos

✨ 特性

  • 🚀 服务注册 - 自动注册服务到 Nacos
  • 🔍 服务发现 - 从 Nacos 发现可用服务
  • ⚙️ 配置中心 - 从 Nacos 读取和监听配置变更
  • 💓 健康检查 - 内置心跳和健康检查

🚀 快速开始

1. 配置 appsettings.json

{
  "Nacos": {
    "ServerAddresses": ["http://localhost:8848"],
    "Namespace": "public",
    "ServiceName": "my-service",
    "GroupName": "DEFAULT_GROUP",
    "ClusterName": "DEFAULT",
    "Ip": "localhost",
    "Port": 5000
  }
}

2. 注册服务

// Program.cs
var builder = WebApplication.CreateBuilder(args);
// 添加SyZero
builder.AddSyZero();

// 注册服务方式1 - 使用配置文件
builder.Configuration.AddNacosConfiguration(builder.Configuration);
builder.Services.AddNacos();

// 注册服务方式2 - 使用委托配置
builder.Services.AddNacos(options =>
{
    options.ServerAddresses = new[] { "http://localhost:8848" };
    options.ServiceName = "my-service";
    options.Port = 5000;
});

// 注册服务方式3 - 添加配置中心
builder.Configuration.AddNacosConfiguration(options =>
{
    options.DataId = "my-service-config";
    options.Group = "DEFAULT_GROUP";
});

var app = builder.Build();
// 使用SyZero
app.UseSyZero();
app.Run();

3. 使用示例

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}";
    }
}

📖 配置选项

属性 类型 默认值 说明
ServerAddresses string[] [] Nacos 服务地址列表
Namespace string "public" 命名空间
ServiceName string "" 服务名称
GroupName string "DEFAULT_GROUP" 分组名称
ClusterName string "DEFAULT" 集群名称

📖 API 说明

IServiceManagement 接口

方法 说明
GetServiceAsync(serviceName) 获取服务实例
GetServicesAsync(serviceName) 获取所有服务实例
RegisterAsync() 注册服务
DeregisterAsync() 注销服务

所有方法都有对应的异步版本(带 Async 后缀)


🔧 高级用法

监听配置变更

builder.Configuration.AddNacosConfiguration(options =>
{
    options.DataId = "my-service-config";
    options.OnConfigChanged = (config) =>
    {
        Console.WriteLine("配置已更新");
    };
});

元数据管理

builder.Services.AddNacos(options =>
{
    options.Metadata = new Dictionary<string, string>
    {
        ["version"] = "1.0.0",
        ["env"] = "production"
    };
});

⚠️ 注意事项

  1. 网络连接 - 确保应用能访问 Nacos 服务
  2. 命名空间 - 不同环境使用不同命名空间隔离
  3. 心跳 - 服务会自动发送心跳保持注册状态

📄 许可证

MIT License - 详见 LICENSE

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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
1.1.5-dev.2 45 2/11/2026
1.1.5-dev.1 49 1/29/2026
1.1.4 105 1/2/2026
1.1.4-dev.2 53 1/2/2026
1.1.4-dev.1 51 12/30/2025
1.1.3 101 12/30/2025
1.1.3-dev.6 54 12/30/2025
1.0.6 446 3/5/2022