Skip to content

Commit 4206bf4

Browse files
author
liguoliang
committed
添加nacos服务注册发现demo
1 parent b87667a commit 4206bf4

4 files changed

Lines changed: 32 additions & 3 deletions

File tree

demo/Test.Client/Program.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ static async Task Main(string[] args)
2828
services.AddLogging()
2929
//单机版Httpclient配置
3030
.AddHttpClient(TestServerName, client => { client.BaseAddress = new Uri("http://localhost:34047"); })
31-
.AddDotNetCoreRpcClient(options => {
31+
.AddDotNetCoreRpcClient(options =>
32+
{
3233
options.Path = "/Test.Server6";
3334
options.AddRpcClient<IPersonService>().AddRpcClient<IProductService>();
3435
});
@@ -37,8 +38,13 @@ static async Task Main(string[] args)
3738
//.AddScoped<NacosDiscoveryDelegatingHandler>()
3839
//.AddHttpClient(TestServerName, client =>
3940
//{
40-
// client.BaseAddress = new Uri($"http://{TestServerName}/Test.Server6");
41-
//}).AddHttpMessageHandler<NacosDiscoveryDelegatingHandler>();
41+
// client.BaseAddress = new Uri($"http://{TestServerName}");
42+
//})
43+
//.AddHttpMessageHandler<NacosDiscoveryDelegatingHandler>()
44+
//.AddDotNetCoreRpcClient(options => {
45+
// options.Path = "/Test.Server6";
46+
// options.AddRpcClient<IPersonService>().AddRpcClient<IProductService>();
47+
//});
4248

4349
using var scope = services.BuildServiceProvider().CreateScope();
4450
IServiceProvider serviceProvider = scope.ServiceProvider;

demo/Test.Server6/Program.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
using DotNetCoreRpc.Server;
2+
using Microsoft.Extensions.Configuration;
3+
using Nacos.AspNetCore.V2;
4+
using Nacos.V2.Naming.Dtos;
25
using Test.DAL;
36
using Test.IDAL;
47
using Test.IService;
@@ -18,6 +21,8 @@
1821
options.AddFilter<CacheFilter>();
1922
});
2023

24+
//builder.Services.AddNacosAspNet(builder.Configuration);
25+
2126
var app = builder.Build();
2227

2328
app.UseDotNetCoreRpc("/Test.Server6");

demo/Test.Server6/Test.Server6.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
</PropertyGroup>
88

9+
<ItemGroup>
10+
<PackageReference Include="nacos-sdk-csharp.AspNetCore" Version="1.1.0" />
11+
</ItemGroup>
12+
913
<ItemGroup>
1014
<ProjectReference Include="..\..\src\DotNetCoreRpc.Server\DotNetCoreRpc.Server.csproj" />
1115
<ProjectReference Include="..\Test.DAL\Test.DAL.csproj" />

demo/Test.Server6/appsettings.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,19 @@
55
"Microsoft.AspNetCore": "Warning"
66
}
77
},
8+
"nacos": {
9+
"ServerAddresses": [ "http://localhost:8848" ],
10+
"ServiceName": "testserver",
11+
"DefaultTimeOut": 15000,
12+
//自定义Namespace的Id
13+
"Namespace": "01761089-727d-49cb-9abe-fbe647f83927",
14+
"GroupName": "DEFAULT_GROUP",
15+
"ClusterName": "DEFAULT",
16+
"ListenInterval": 1000,
17+
"RegisterEnabled": true,
18+
"InstanceEnabled": true,
19+
"LBStrategy": "WeightRandom",
20+
"NamingUseRpc": true
21+
},
822
"AllowedHosts": "*"
923
}

0 commit comments

Comments
 (0)