Orleans[NET Core 3.1] 学习笔记(三)( 2 )客户端配置

客户端配置

经过一个ClientBuilder和多个补充选项类,以编程方式配置一个用于链接Silo集群并将请求发送至Grain的客户端。html

客户端配置示例:git

var client = new ClientBuilder()
    // 集群信息
    .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(IHello).Assembly))
    .Build();

注意:使用UseAzureStorageClustering须要引用Microsoft.Orleans.Clustering.AzureStoragegithub

下面让咱们细分该示例中使用的步骤:docker

集群信息

[...]
    // Clustering information
    .Configure<ClusterOptions>(options =>
    {
        options.ClusterId = "orleans-docker";
        options.ServiceId = "AspNetSampleApp";
    })
    [...]

这里咱们使用了两个设置:编程

设置ClusterId"my-first-cluster":这是为Orleans集群的惟一ID。使用此ID的全部客户端和Silo将可以直接相互通讯。例如,有些人会选择ClusterId对每一个部署使用不一样的名称。
设置ServiceId"AspNetSampleApp":这是你的应用程序的惟一ID,将被一些控制程序使用(例如用于持久性存储)。该ID在整个部署中应该是稳定的(不可更改)服务器

集群支撑程序

[...]
    // Clustering provider
    .UseAzureStorageClustering(options => options.ConnectionString = connectionString)
    [...]

客户端将使用此程序配置发现群集中全部可用的网关。Orleans有几个支撑程序能够选择,在此示例中,咱们使用Azure Table提供程序。分布式

要获取更多详细信息,请查看“服务器配置”页面中的“Server Configuration”部分。ide

应用部分

[...]
    // Application parts: just reference one of the grain interfaces that we use
    .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IHello).Assembly)).WithReferences())
    [...];

便捷路由

目录Orleans[NET Core 3.1] 学习笔记(一).NET环境下的分布式应用程序学习

上一节Orleans[NET Core 3.1] 学习笔记(三)( 1 )本地开发配置ui

下一节

相关文章
相关标签/搜索