客戶端配置
通過一個ClientBuilder
和多個補充選項類,以編程方式配置一個用於連接Silo集群並將請求發送至Grain的客戶端。
客戶端配置示例:
var client = new ClientBuilder()
// 集群信息
.Configure<ClusterOptions>(options =>
{
options.ClusterId = "my-first-cluster";
options.ServiceId = "MyOrleansService";
})
// 群集提供程序
.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.AzureStorage
下面讓我們細分該示例中使用的步驟:
集群信息
[...]
// Clustering information
.Configure<ClusterOptions>(options =>
{
options.ClusterId = "orleans-docker";
options.ServiceId = "AspNetSampleApp";
})
//客戶端連接非本地的網關,配置這個就行了,可以配置多個網關
.UseStaticClustering(new IPEndPoint[] { new IPEndPoint(IPAddress.Parse(""), 30000) })
[...]
這里我們使用了兩個設置:
設置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”部分。
應用部分
[...]
// 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環境下的分布式應用程序