From ca23dc6e24d5adee34e3f61edbb953c92496c273 Mon Sep 17 00:00:00 2001 From: catcherwong Date: Sun, 21 Feb 2021 15:59:26 +0800 Subject: [PATCH] update docs --- README.md | 74 ++++-- README.zh-cn.md | 73 ++++-- ...Guidelines for upgrading to version 1.0.md | 232 +++++++++++++++++ ...10\346\234\254\346\214\207\345\274\225.md" | 234 ++++++++++++++++++ 4 files changed, 564 insertions(+), 49 deletions(-) create mode 100644 docs/Guidelines for upgrading to version 1.0.md create mode 100644 "docs/zh-cn/\345\215\207\347\272\247\345\210\2601.0\347\211\210\346\234\254\346\214\207\345\274\225.md" diff --git a/README.md b/README.md index 6677e11..f7dd278 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ csharp(dotnet core) implementation of [nacos](https://nacos.io/) OpenAPI. -![Build](https://github.com/nacos-group/nacos-sdk-csharp/workflows/Build/badge.svg) ![Release](https://github.com/nacos-group/nacos-sdk-csharp/workflows/Release/badge.svg) ![](https://img.shields.io/nuget/v/nacos-sdk-csharp-unofficial.svg) ![](https://img.shields.io/nuget/vpre/nacos-sdk-csharp-unofficial.svg) ![](https://img.shields.io/nuget/dt/nacos-sdk-csharp-unofficial) ![](https://img.shields.io/github/license/nacos-group/nacos-sdk-csharp) +![Build](https://github.com/nacos-group/nacos-sdk-csharp/workflows/Build/badge.svg) ![Release](https://github.com/nacos-group/nacos-sdk-csharp/workflows/Release/badge.svg) ![](https://img.shields.io/nuget/v/nacos-sdk-csharp.svg) ![](https://img.shields.io/nuget/vpre/nacos-sdk-csharp.svg) ![](https://img.shields.io/nuget/dt/nacos-sdk-csharp) ![](https://img.shields.io/github/license/nacos-group/nacos-sdk-csharp) ![](./media/prj.png) @@ -11,13 +11,15 @@ csharp(dotnet core) implementation of [nacos](https://nacos.io/) OpenAPI. Choose a package that you need. ```bash -dotnet add package nacos-sdk-csharp-unofficial -dotnet add package nacos-sdk-csharp-unofficial.AspNetCore -dotnet add package nacos-sdk-csharp-unofficial.Extensions.Configuration -dotnet add package nacos-sdk-csharp-unofficial.YamlParser -dotnet add package nacos-sdk-csharp-unofficial.IniParser +dotnet add package nacos-sdk-csharp +dotnet add package nacos-sdk-csharp.AspNetCore +dotnet add package nacos-sdk-csharp.Extensions.Configuration +dotnet add package nacos-sdk-csharp.YamlParser +dotnet add package nacos-sdk-csharp.IniParser ``` +> NOTE: The packages' name has remove the suffix `unofficial`. + ## Features - Basic OpenApi Usages @@ -41,7 +43,7 @@ public static IHostBuilder CreateHostBuilder(string[] args) => // read configuration from config files // it will use default json parser to parse the configuration store in nacos server. - builder.AddNacosConfiguration(c.GetSection("NacosConfig")); + builder.AddNacosV2Configuration(c.GetSection("NacosConfig")); // you also can specify ini or yaml parser as well. // builder.AddNacosConfiguration(c.GetSection("NacosConfig"), Nacos.IniParser.IniConfigurationStringParser.Instance); // builder.AddNacosConfiguration(c.GetSection("NacosConfig"), Nacos.YamlParser.YamlConfigurationStringParser.Instance); @@ -57,16 +59,25 @@ public static IHostBuilder CreateHostBuilder(string[] args) => ```JSON { "NacosConfig": { - "Optional": false, - "DataId": "msconfigapp", - "Group": "", - "Tenant": "f47e0ae1-982a-4a64-aea3-52506492a3d4", + "Listeners": [ + { + "Optional": false, + "DataId": "common", + "Group": "DEFAULT_GROUP" + }, + { + "Optional": false, + "DataId": "demo", + "Group": "DEFAULT_GROUP" + } + ], + "Tenant": "csharp-demo", "ServerAddresses": [ "http://localhost:8848/" ], "UserName": "test2", "Password": "123456", "AccessKey": "", "SecretKey": "", - "EndPoint": "acm.aliyun.com:8080" + "EndPoint": "acm.aliyun.com" } } ``` @@ -128,7 +139,7 @@ public class Startup { // ... - services.AddNacosAspNetCore(Configuration); + services.AddNacosAspNet(Configuration); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) @@ -142,20 +153,29 @@ Modify `appsettings.json` ```JSON "nacos": { + "EndPoint": "sub-domain.aliyun.com:8080", "ServerAddresses": [ "http://localhost:8848" ], "DefaultTimeOut": 15000, - "Namespace": "", + "Namespace": "cs", "ListenInterval": 1000, "ServiceName": "App1", - "ClusterName": "", - "GroupName": "", - "Weight": 100, + "GroupName": "DEFAULT_GROUP", + "ClusterName": "DEFAULT", + "Ip": "", "PreferredNetworks": "", // select an IP that matches the prefix as the service registration IP - "UserName": "test2", - "Password": "123456", + "Port": 0, + "Weight": 100, + "RegisterEnabled": true, + "InstanceEnabled": true, + "Ephemeral": true, + "Secure": false, "AccessKey": "", "SecretKey": "", - "EndPoint": "sub-domain.aliyun.com:8080", + "UserName": "", + "Password": "", + "ConfigUseRpc": true, + "NamingUseRpc": true, + "NamingLoadCacheAtStart": "", "LBStrategy": "WeightRandom", //WeightRandom WeightRoundRobin "Metadata": { "aa": "bb", @@ -171,19 +191,23 @@ Modify `appsettings.json` [ApiController] public class ValuesController : ControllerBase { - private readonly INacosServerManager _serverManager; + private readonly Nacos.V2.INacosNamingService _svc; - public ValuesController(INacosServerManager serverManager) + public ValuesController(Nacos.V2.INacosNamingService svc) { - _serverManager = serverManager; + _svc = svc; } [HttpGet("test")] public async Task Test() { // need to know the service name. - // support WeightRandom and WeightRoundRobin. - var baseUrl = await _serverManager.GetServerAsync("App2"); + var instance = await _svc.SelectOneHealthyInstance("App2", "DEFAULT_GROUP"); + var host = $"{instance.Ip}:{instance.Port}"; + + var baseUrl = instance.Metadata.TryGetValue("secure", out _) + ? $"https://{host}" + : $"http://{host}"; if(string.IsNullOrWhiteSpace(baseUrl)) { diff --git a/README.zh-cn.md b/README.zh-cn.md index 6df2cc0..0d6e54b 100644 --- a/README.zh-cn.md +++ b/README.zh-cn.md @@ -2,7 +2,8 @@ 基于C#(dotnet core)实现 [nacos](https://nacos.io/) OpenAPI 的官方版本 -![Build](https://github.com/nacos-group/nacos-sdk-csharp/workflows/Build/badge.svg) ![Release](https://github.com/nacos-group/nacos-sdk-csharp/workflows/Release/badge.svg) ![](https://img.shields.io/nuget/v/nacos-sdk-csharp-unofficial.svg) ![](https://img.shields.io/nuget/vpre/nacos-sdk-csharp-unofficial.svg) ![](https://img.shields.io/nuget/dt/nacos-sdk-csharp-unofficial) ![](https://img.shields.io/github/license/nacos-group/nacos-sdk-csharp) +![Build](https://github.com/nacos-group/nacos-sdk-csharp/workflows/Build/badge.svg) ![Release](https://github.com/nacos-group/nacos-sdk-csharp/workflows/Release/badge.svg) ![](https://img.shields.io/nuget/v/nacos-sdk-csharp.svg) ![](https://img.shields.io/nuget/vpre/nacos-sdk-csharp.svg) ![](https://img.shields.io/nuget/dt/nacos-sdk-csharp) ![](https://img.shields.io/github/license/nacos-group/nacos-sdk-csharp) + ![](./media/prj.png) @@ -11,13 +12,15 @@ 选择您需要的包。 ```bash -dotnet add package nacos-sdk-csharp-unofficial -dotnet add package nacos-sdk-csharp-unofficial.AspNetCore -dotnet add package nacos-sdk-csharp-unofficial.Extensions.Configuration -dotnet add package nacos-sdk-csharp-unofficial.YamlParser -dotnet add package nacos-sdk-csharp-unofficial.IniParser +dotnet add package nacos-sdk-csharp +dotnet add package nacos-sdk-csharp.AspNetCore +dotnet add package nacos-sdk-csharp.Extensions.Configuration +dotnet add package nacos-sdk-csharp.YamlParser +dotnet add package nacos-sdk-csharp.IniParser ``` +> 注: 包名里面的`unofficial`后缀已经被移除。 + ## 功能特性 - 基本的Open Api接口封装 @@ -41,7 +44,7 @@ public static IHostBuilder CreateHostBuilder(string[] args) => // 从配置文件读取Nacos相关配置 // 默认会使用JSON解析器来解析存在Nacos Server的配置 - builder.AddNacosConfiguration(c.GetSection("NacosConfig")); + builder.AddNacosV2Configuration(c.GetSection("NacosConfig")); // 也可以按需使用ini或yaml的解析器 // builder.AddNacosConfiguration(c.GetSection("NacosConfig"), Nacos.IniParser.IniConfigurationStringParser.Instance); // builder.AddNacosConfiguration(c.GetSection("NacosConfig"), Nacos.YamlParser.YamlConfigurationStringParser.Instance); @@ -57,10 +60,19 @@ public static IHostBuilder CreateHostBuilder(string[] args) => ```JSON { "NacosConfig": { - "Optional": false, - "DataId": "msconfigapp", - "Group": "", - "Tenant": "f47e0ae1-982a-4a64-aea3-52506492a3d4", + "Listeners": [ + { + "Optional": false, + "DataId": "common", + "Group": "DEFAULT_GROUP" + }, + { + "Optional": false, + "DataId": "demo", + "Group": "DEFAULT_GROUP" + } + ], + "Tenant": "csharp-demo", "ServerAddresses": [ "http://localhost:8848/" ], "UserName": "test2", "Password": "123456", @@ -128,7 +140,7 @@ public class Startup { // ... - services.AddNacosAspNetCore(Configuration); + services.AddNacosAspNet(Configuration); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) @@ -142,20 +154,29 @@ public class Startup ```JSON "nacos": { + "EndPoint": "sub-domain.aliyun.com:8080", "ServerAddresses": [ "http://localhost:8848" ], "DefaultTimeOut": 15000, - "Namespace": "", + "Namespace": "cs", "ListenInterval": 1000, "ServiceName": "App1", - "ClusterName": "", - "GroupName": "", - "Weight": 100, + "GroupName": "DEFAULT_GROUP", + "ClusterName": "DEFAULT", + "Ip": "", "PreferredNetworks": "", // select an IP that matches the prefix as the service registration IP - "UserName": "test2", - "Password": "123456", + "Port": 0, + "Weight": 100, + "RegisterEnabled": true, + "InstanceEnabled": true, + "Ephemeral": true, + "Secure": false, "AccessKey": "", "SecretKey": "", - "EndPoint": "sub-domain.aliyun.com:8080", + "UserName": "", + "Password": "", + "ConfigUseRpc": true, + "NamingUseRpc": true, + "NamingLoadCacheAtStart": "", "LBStrategy": "WeightRandom", //WeightRandom WeightRoundRobin "Metadata": { "aa": "bb", @@ -171,19 +192,23 @@ public class Startup [ApiController] public class ValuesController : ControllerBase { - private readonly INacosServerManager _serverManager; + private readonly Nacos.V2.INacosNamingService _svc; - public ValuesController(INacosServerManager serverManager) + public ValuesController(Nacos.V2.INacosNamingService svc) { - _serverManager = serverManager; + _svc = svc; } [HttpGet("test")] public async Task Test() { // 这里需要知道被调用方的服务名 - // 支持加权随机和加权轮询 - var baseUrl = await _serverManager.GetServerAsync("App2"); + var instance = await _svc.SelectOneHealthyInstance("App2", "DEFAULT_GROUP") + var host = $"{instance.Ip}:{instance.Port}"; + + var baseUrl = instance.Metadata.TryGetValue("secure", out _) + ? $"https://{host}" + : $"http://{host}"; if(string.IsNullOrWhiteSpace(baseUrl)) { diff --git a/docs/Guidelines for upgrading to version 1.0.md b/docs/Guidelines for upgrading to version 1.0.md new file mode 100644 index 0000000..02f33f0 --- /dev/null +++ b/docs/Guidelines for upgrading to version 1.0.md @@ -0,0 +1,232 @@ +# Guidelines for upgrading to version 1.0 + +## Background + +Before `nacos-sdk-csharp` v1.0.0, it was mainly connected to Nacos server 1. X. + +With the release of Nacos server 2.0.0, `nacos-sdk-csharp` has been reconstructed and adapted to dock. + +Because the protocol of Nacos server from 1.X to 2.X is changed, 1.X is mainly HTTP, 2.X is mainly grpc. + +Before, the SDK mainly encapsulated and supplemented some contents of open API. + +In version 1.0.0, the SDK method will align with the Java version of the SDK. The adjustment here will be relatively large, but several versions of the previous method will be retained. + +## Upgrade + +The premise is that the version of nacos server is 2.0.0 or higher. + +Modify the referenced nuget package + +```diff + +- ++ + +``` + +> NOTE: The suffix "unofficial" has been removed from the package name. The version 1.0.0 is still prereleased, so there will be alpha, which will not be available after the official release. If you depend on the extension package, you need to do the corresponding processing. + +The basic configuration is as follows: + +```json +{ + "EndPoint": "", + "ServerAddresses": [ "http://localhost:8848" ], + "DefaultTimeOut": 15000, + "Namespace": "cs", + "ListenInterval": 1000, + "AccessKey": "", + "SecretKey": "", + "UserName": "", + "Password": "", + "ConfigUseRpc": true, + "NamingUseRpc": true, + "NamingLoadCacheAtStart": "" +} +``` + +Only when 'ConfigUseRpc' and 'NamingUseRpc' are set to true, gPRC will be used to interact with Nacos server, otherwise HTTP will be used. + +## Configuration changes + +### SDK + +Adjust `INacosConfigClient` to `INacosConfigService`, and it providers the following methods. + +```cs +Task GetConfig(string dataId, string group, long timeoutMs); + +Task GetConfigAndSignListener(string dataId, string group, long timeoutMs, IListener listener); + +Task AddListener(string dataId, string group, IListener listener); + +Task PublishConfig(string dataId, string group, string content); + +Task PublishConfig(string dataId, string group, string content, string type); + +Task RemoveConfig(string dataId, string group); + +Task RemoveListener(string dataId, string group, IListener listener); + +Task GetServerStatus(); + +Task ShutDown(); +``` + +### Integrate ASP.NET Core + +```diff + Host.CreateDefaultBuilder(args) + .ConfigureAppConfiguration((context, builder) => + { + var c = builder.Build(); +- builder.AddNacosConfiguration(c.GetSection("NacosConfig")); ++ builder.AddNacosV2Configuration(c.GetSection("NacosConfig")); + }) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }) +``` + + +## Service changes + +### SDK + +Adjust `INacosNamingClient` to `INacosNamingService`, and it providers the following methods. + +```cs +Task RegisterInstance(string serviceName, string ip, int port); + +Task RegisterInstance(string serviceName, string groupName, string ip, int port); + +Task RegisterInstance(string serviceName, string ip, int port, string clusterName); + +Task RegisterInstance(string serviceName, string groupName, string ip, int port, string clusterName); + +Task RegisterInstance(string serviceName, Instance instance); + +Task RegisterInstance(string serviceName, string groupName, Instance instance); + +Task DeregisterInstance(string serviceName, string ip, int port); + +Task DeregisterInstance(string serviceName, string groupName, string ip, int port); + +Task DeregisterInstance(string serviceName, string ip, int port, string clusterName); + +Task DeregisterInstance(string serviceName, string groupName, string ip, int port, string clusterName); + +Task DeregisterInstance(string serviceName, Instance instance); + +Task DeregisterInstance(string serviceName, string groupName, Instance instance); + +Task> GetAllInstances(string serviceName); + +Task> GetAllInstances(string serviceName, string groupName); + +Task> GetAllInstances(string serviceName, bool subscribe); + +Task> GetAllInstances(string serviceName, string groupName, bool subscribe); + +Task> GetAllInstances(string serviceName, List clusters); + +Task> GetAllInstances(string serviceName, string groupName, List clusters); + +Task> GetAllInstances(string serviceName, List clusters, bool subscribe); + +Task> GetAllInstances(string serviceName, string groupName, List clusters, bool subscribe); + +Task> SelectInstances(string serviceName, bool healthy); + +Task> SelectInstances(string serviceName, string groupName, bool healthy); + +Task> SelectInstances(string serviceName, bool healthy, bool subscribe); + +Task> SelectInstances(string serviceName, string groupName, bool healthy, bool subscribe); + +Task> SelectInstances(string serviceName, List clusters, bool healthy); + +Task> SelectInstances(string serviceName, string groupName, List clusters, bool healthy); + +Task> SelectInstances(string serviceName, List clusters, bool healthy, bool subscribe); + +Task> SelectInstances(string serviceName, string groupName, List clusters, bool healthy, bool subscribe); + +Task SelectOneHealthyInstance(string serviceName); + +Task SelectOneHealthyInstance(string serviceName, string groupName); + +Task SelectOneHealthyInstance(string serviceName, bool subscribe); + +Task SelectOneHealthyInstance(string serviceName, string groupName, bool subscribe); + +Task SelectOneHealthyInstance(string serviceName, List clusters); + +Task SelectOneHealthyInstance(string serviceName, string groupName, List clusters); + +Task SelectOneHealthyInstance(string serviceName, List clusters, bool subscribe); + +Task SelectOneHealthyInstance(string serviceName, string groupName, List clusters, bool subscribe); + +Task Subscribe(string serviceName, IEventListener listener); + +Task Subscribe(string serviceName, string groupName, IEventListener listener); + +Task Subscribe(string serviceName, List clusters, IEventListener listener); + +Task Subscribe(string serviceName, string groupName, List clusters, IEventListener listener); + +Task Unsubscribe(string serviceName, IEventListener listener); + +Task Unsubscribe(string serviceName, string groupName, IEventListener listener); + +Task Unsubscribe(string serviceName, List clusters, IEventListener listener); + +Task Unsubscribe(string serviceName, string groupName, List clusters, IEventListener listener); + +Task> GetServicesOfServer(int pageNo, int pageSize); + +Task> GetServicesOfServer(int pageNo, int pageSize, string groupName); + +Task> GetServicesOfServer(int pageNo, int pageSize, AbstractSelector selector); + +Task> GetServicesOfServer(int pageNo, int pageSize, string groupName, AbstractSelector selector); + +Task> GetSubscribeServices(); + +Task GetServerStatus(); + +Task ShutDown(); +``` + +### Integrate ASP.NET Core + +Modify `Startup` + +```diff + public void ConfigureServices(IServiceCollection services) + { +- services.AddNacosAspNetCore(Configuration); ++ services.AddNacosAspNet(Configuration); + services.AddControllers(); + } +``` + +From `INacosServerManager` to `INacosNamingService`。 + +Details: + +```diff +- var baseUrl = await _serverManager.GetServerAsync("App2"); + ++ var instance = await _svc.SelectOneHealthyInstance("App2", "DEFAULT_GROUP"); ++ var host = $"{instance.Ip}:{instance.Port}"; + ++ var baseUrl = instance.Metadata.TryGetValue("secure", out _) ++ ? $"https://{host}" ++ : $"http://{host}"; +``` + +On the basis of the original service configuration, three options are added: **InstanceEnabled**, **Ephemeral**, **Secure**. diff --git "a/docs/zh-cn/\345\215\207\347\272\247\345\210\2601.0\347\211\210\346\234\254\346\214\207\345\274\225.md" "b/docs/zh-cn/\345\215\207\347\272\247\345\210\2601.0\347\211\210\346\234\254\346\214\207\345\274\225.md" new file mode 100644 index 0000000..1f6528a --- /dev/null +++ "b/docs/zh-cn/\345\215\207\347\272\247\345\210\2601.0\347\211\210\346\234\254\346\214\207\345\274\225.md" @@ -0,0 +1,234 @@ +# 升级到1.0版本指引 + +## 背景 + +`nacos-sdk-csharp` v1.0.0 版本之前主要是对接 nacos server 1.x。 + +随着 nacos server 2.0.0 即将发布,`nacos-sdk-csharp` 也已经进行了一次重构和适配来对接。 + +由于 nacos server 从 1.x 到 2.x 客户端对接的协议有所变更,1.x主要是HTTP, 2.x主要是gRPC。 + +之前 sdk 主要是对 Open Api 进行了封装和补充了部分内容。 + +在 1.0.0 版本,sdk 的方法会对齐 java版的 sdk, 这里的调整会比较大,但是之前用的方法还会保留几个版本。 + +## 升级 + +大前提是 nacos server 版本已经是 2.0.0或更高版本。 + +修改引用的 nuget 包 + +```diff + +- ++ + +``` + +> 注: 包名已经移除了 `unofficial` 的后缀,1.0.0的版本目前还是prerelease,所以会有alpha的字样,正式发布后是没有的。如果依赖了扩展包,也需要做对应的处理。 + +核心的基础配置如下: + +```json +{ + "EndPoint": "", + "ServerAddresses": [ "http://localhost:8848" ], + "DefaultTimeOut": 15000, + "Namespace": "cs", + "ListenInterval": 1000, + "AccessKey": "", + "SecretKey": "", + "UserName": "", + "Password": "", + "ConfigUseRpc": true, + "NamingUseRpc": true, + "NamingLoadCacheAtStart": "" +} +``` + +只有当 `ConfigUseRpc` 和 `NamingUseRpc` 设置为true的时候,才会用 gRPC 去和 nacos server 交互, 反之还是 HTTP。 + +## 配置变化 + +### SDK + +代码层使用的 `INacosConfigClient` 需要调整成 `INacosConfigService`, 提供了如下的方法。 + +```cs +Task GetConfig(string dataId, string group, long timeoutMs); + +Task GetConfigAndSignListener(string dataId, string group, long timeoutMs, IListener listener); + +Task AddListener(string dataId, string group, IListener listener); + +Task PublishConfig(string dataId, string group, string content); + +Task PublishConfig(string dataId, string group, string content, string type); + +Task RemoveConfig(string dataId, string group); + +Task RemoveListener(string dataId, string group, IListener listener); + +Task GetServerStatus(); + +Task ShutDown(); +``` + +### 集成ASP.NET Core + +主要是变更 `ConfigureAppConfiguration` 里面的 AddNacosConfiguration,其余的不需要变化。 + +```diff + Host.CreateDefaultBuilder(args) + .ConfigureAppConfiguration((context, builder) => + { + var c = builder.Build(); +- builder.AddNacosConfiguration(c.GetSection("NacosConfig")); ++ builder.AddNacosV2Configuration(c.GetSection("NacosConfig")); + }) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }) +``` + + +## 服务变化 + +### SDK + +代码层使用的 `INacosNamingClient` 需要调整成 `INacosNamingService`, 提供了如下的方法。 + +```cs +Task RegisterInstance(string serviceName, string ip, int port); + +Task RegisterInstance(string serviceName, string groupName, string ip, int port); + +Task RegisterInstance(string serviceName, string ip, int port, string clusterName); + +Task RegisterInstance(string serviceName, string groupName, string ip, int port, string clusterName); + +Task RegisterInstance(string serviceName, Instance instance); + +Task RegisterInstance(string serviceName, string groupName, Instance instance); + +Task DeregisterInstance(string serviceName, string ip, int port); + +Task DeregisterInstance(string serviceName, string groupName, string ip, int port); + +Task DeregisterInstance(string serviceName, string ip, int port, string clusterName); + +Task DeregisterInstance(string serviceName, string groupName, string ip, int port, string clusterName); + +Task DeregisterInstance(string serviceName, Instance instance); + +Task DeregisterInstance(string serviceName, string groupName, Instance instance); + +Task> GetAllInstances(string serviceName); + +Task> GetAllInstances(string serviceName, string groupName); + +Task> GetAllInstances(string serviceName, bool subscribe); + +Task> GetAllInstances(string serviceName, string groupName, bool subscribe); + +Task> GetAllInstances(string serviceName, List clusters); + +Task> GetAllInstances(string serviceName, string groupName, List clusters); + +Task> GetAllInstances(string serviceName, List clusters, bool subscribe); + +Task> GetAllInstances(string serviceName, string groupName, List clusters, bool subscribe); + +Task> SelectInstances(string serviceName, bool healthy); + +Task> SelectInstances(string serviceName, string groupName, bool healthy); + +Task> SelectInstances(string serviceName, bool healthy, bool subscribe); + +Task> SelectInstances(string serviceName, string groupName, bool healthy, bool subscribe); + +Task> SelectInstances(string serviceName, List clusters, bool healthy); + +Task> SelectInstances(string serviceName, string groupName, List clusters, bool healthy); + +Task> SelectInstances(string serviceName, List clusters, bool healthy, bool subscribe); + +Task> SelectInstances(string serviceName, string groupName, List clusters, bool healthy, bool subscribe); + +Task SelectOneHealthyInstance(string serviceName); + +Task SelectOneHealthyInstance(string serviceName, string groupName); + +Task SelectOneHealthyInstance(string serviceName, bool subscribe); + +Task SelectOneHealthyInstance(string serviceName, string groupName, bool subscribe); + +Task SelectOneHealthyInstance(string serviceName, List clusters); + +Task SelectOneHealthyInstance(string serviceName, string groupName, List clusters); + +Task SelectOneHealthyInstance(string serviceName, List clusters, bool subscribe); + +Task SelectOneHealthyInstance(string serviceName, string groupName, List clusters, bool subscribe); + +Task Subscribe(string serviceName, IEventListener listener); + +Task Subscribe(string serviceName, string groupName, IEventListener listener); + +Task Subscribe(string serviceName, List clusters, IEventListener listener); + +Task Subscribe(string serviceName, string groupName, List clusters, IEventListener listener); + +Task Unsubscribe(string serviceName, IEventListener listener); + +Task Unsubscribe(string serviceName, string groupName, IEventListener listener); + +Task Unsubscribe(string serviceName, List clusters, IEventListener listener); + +Task Unsubscribe(string serviceName, string groupName, List clusters, IEventListener listener); + +Task> GetServicesOfServer(int pageNo, int pageSize); + +Task> GetServicesOfServer(int pageNo, int pageSize, string groupName); + +Task> GetServicesOfServer(int pageNo, int pageSize, AbstractSelector selector); + +Task> GetServicesOfServer(int pageNo, int pageSize, string groupName, AbstractSelector selector); + +Task> GetSubscribeServices(); + +Task GetServerStatus(); + +Task ShutDown(); +``` + +### 集成ASP.NET Core + +调整 `Startup` + +```diff + public void ConfigureServices(IServiceCollection services) + { +- services.AddNacosAspNetCore(Configuration); ++ services.AddNacosAspNet(Configuration); + services.AddControllers(); + } +``` + +用到 `INacosServerManager` 的地方需要换成 `INacosNamingService`。 + +具体使用如下: + +```diff +- var baseUrl = await _serverManager.GetServerAsync("App2"); + ++ var instance = await _svc.SelectOneHealthyInstance("App2", "DEFAULT_GROUP"); ++ var host = $"{instance.Ip}:{instance.Port}"; + ++ var baseUrl = instance.Metadata.TryGetValue("secure", out _) ++ ? $"https://{host}" ++ : $"http://{host}"; +``` + +服务的配置,在原先的基础上添加了, **InstanceEnabled**, **Ephemeral**, **Secure** 三个内容。