一些orleans的设置
DirectClient模式 - InProcessSilo模式
Orleans 2.1引入了新的Direct Client模式:
The feature is called direct client and it allows co-hosting a client and silo in a way that let the client communicate more efficiently with not just the silo it’s attached to, but the entire cluster
也可以用来在一开始简化部署,简化开发等目的
核心思想是IClusterClient 要从ISiloHost的依赖注入容器中获取:
dotnet core 2.x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28var silo = new SiloHostBuilder().UseLocalhostClustering()
.ConfigureApplicationParts(parts =>
parts.AddApplicationPart(typeof(XxxGrain).Assembly).WithReferences()
.WithCodeGeneration())
.ConfigureLogging(x =>
{
x.AddConsole();
x.SetMinimumLevel(LogLevel.Error);
})
.ConfigureServices(services =>
{
// services here
})
.Build();
await silo.StartAsync();
var client = silo.Services.GetRequiredService<IClusterClient>();
await WebHost.CreateDefaultBuilder(args)
.UseConfiguration(new ConfigurationBuilder()
.AddCommandLine(args)
.Build())
.ConfigureServices(services =>
services
.AddSingleton<IGrainFactory>(client)
.AddSingleton<IClusterClient>(client))
.UseStartup<Startup>()
.Build()
.RunAsync();
一般Silo可以在启动时初始化,或者作为 .net core的HostedService在后台运行,这样可以避免一些配置难以处理
- dotnet core3.0 & Orleans 2.3
1
2
3
4
5
6
7
8
9
10
11
12var host = new HostBuilder()
.ConfigureWebHost(builder =>
{
builder.UseStartup<Startup>();
})
.UseOrleans(builder =>
{
builder.UseLocalhostClustering();
})
.Build();
await host.StartAsync();
主要区别在于3.0中两个HostBuilder和依赖注入的container都变成了一个。
OrleansDashboard设置
地址: https://github.com/OrleansContrib/OrleansDashboard
一般的配置直接看Readme即可,下面主要介绍一下当HostSelf=false的时候的一些设置
当HostSelf设置为False的时候,即dashboard应该为你的项目的一部分,而不是自己启动一个监听独立的端口。
需要在asp .net core的ConfigureServices中
1
services.AddServicesForSelfHostedDashboard(),
同时注入的services中必须要有GrainFactory, 且该GrainFactory所对应的IClusterClient必须成功连接Silo。
在Configure方法中添加
1
app.UseOrleansDashboard(new DashboardOptions { BasePath = "/dashboard" });
这样dashboard的访问地址为: domain:port/dashboard