引入 NuGet 包
nacos-sdk-csharp.AspNetCore
注册 Nacos 服务
public void ConfigureServices(IServiceCollection services)
{
#region 注册 Nacos 服务
services.AddNacosAspNet(Configuration, "nacos");
#endregion
}
修改 appsettings.json
"nacos": {
//"EndPoint": "sub-domain.aliyun.com:8080",//终点
"ServerAddresses": [ "http://localhost:8848" ], //服务器地址
"DefaultTimeOut": 15000, //默认超时
"Namespace": "57fe759b-d357-49c9-826e-bc9cc663f622", // 这里请设置 Namespace ID 的值!!!!!!!!
"ListenInterval": 1000, //侦听间隔时间
"ServiceName": "Ocelot-Service", //服务名称
"GroupName": "DEFAULT_GROUP", //组名
"ClusterName": "DEFAULT", //群集名称
"Ip": "",
"PreferredNetworks": "", //选择与前缀匹配的IP作为服务注册IP
"Port": 0,
"Weight": 100, //权重
"RegisterEnabled": true, //已启用寄存器
"InstanceEnabled": true, //实例已启用
"Ephemeral": true, //短暂的
"Secure": false, //保护
"AccessKey": "", //访问密钥
"SecretKey": "", //SecretKey(密钥)
"UserName": "", //用户名
"Password": "",
"ConfigUseRpc": true, //配置使用Rpc
"NamingUseRpc": true, //命名使用Rpc
"NamingLoadCacheAtStart": "", //名称开始时加载缓存
"LBStrategy": "WeightRandom", //策略 WeightRandom:权重随机 WeightRoundRobin:权重轮询
"Metadata": { //元数据
"aa": "bb",
"cc": "dd"
}