注意
如果您只想启动本地silo和本地客户端以进行开发,请查看上一章节: “本地开发配置”。
客户端配置
通过一个ClientBuilder
和多个补充选项类,以编程方式配置用于连接到一个silo集群并向grain发送请求的客户端。与silo选项一样,客户机选项类也遵循ASP.NET选项。
客户端配置有几个关键方面:
- Orleans集群信息
- 集群提供者
- 应用部分
客户端配置示例:
var client = new ClientBuilder()
// Clustering information
.Configure<ClusterOptions>(options =>
{
options.ClusterId = "my-first-cluster";
options.ServiceId = "MyOrleansService";
})
// Clustering provider
.UseAzureStorageClustering(options => options.ConnectionString = connectionString)
// Application parts: just reference one of the grain interfaces that we use
.ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IValueGrain).Assembly))
.Build();
我们将分析此示例中使用的步骤:
Orleans集群信息
[...]
// Clustering information
.Configure<ClusterOptions>(options =>
{
options.ClusterId = "orleans-docker";
options.ServiceId = "AspNetSampleApp";
})
[...]
在这里我们设置两件事:
将ClusterId
设置为"orleans-docker"
:这是Orleans集群的唯一ID。所有使用此ID的客户端和silo都将能够直接相互通信。举例来说,有些人会选择为每个部署使用不同的ClusterId
。将ServiceId设置为
"AspNetSampleApp"
:这是你的应用程序,将被一些提供程序使用(例如持久化提供程序)的唯一ID。此ID在部署中应该是稳定的(不会更改)。
集群提供者
[...]
// Clustering provider
.UseAzureStorageClustering(options => options.ConnectionString = connectionString)
[...]
客户端将使用此提供程序来发现群集中所有可用的网关。有几个提供程序可用,在此示例中我们使用Azure Table提供程序。
要获得更多详细信息,请查看“服务器配置”章节中的相关内容。
应用部分
[...]
// Application parts: just reference one of the grain interfaces that we use
.ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IValueGrain).Assembly)).WithReferences())
[...];
要获得更多详细信息,请查看“服务器配置”章节中的相关内容。