Share via


用戶端組態

連線到定址接收器叢集並將要求傳送至粒紋的用戶端會透過 IHostBuilder 和數個補充選項類別,以程式設計方式進行設定。 如同定址接收器選項,用戶端選項類別會遵循 .NET 中的選項模式

連線到定址接收器叢集並將要求傳送至粒紋的用戶端會透過 ClientBuilder 和數個補充選項類別,以程式設計方式進行設定。 如同定址接收器選項,用戶端選項類別會遵循 .NET 中的選項模式

提示

如果您只想啟動本機定址接收器和本機用戶端以供開發之用,請參閱本機開發組態

Microsoft.Orleans.Clustering.AzureStorage NuGet 封裝新增至用戶端專案。

定址接收器組態有數個主要層面:

  • Orleans 叢集資訊
  • 叢集提供者
  • 應用程式組件

用戶端組態的範例:

var client = new HostBuilder()
    .UseOrleansClient((context, clientBuilder) =>
    {
        clientBuilder.Configure<ClusterOptions>(options =>
        {
            options.ClusterId = "my-first-cluster";
            options.ServiceId = "MyOrleansService";
        })
        .UseAzureStorageClustering(
            options => options.ConfigureTableServiceClient(
                context.Configuration["ORLEANS_AZURE_STORAGE_CONNECTION_STRING"]));
    })
    .Build();
using Orleans.Hosting;

var client = new ClientBuilder()
    .Configure<ClusterOptions>(options =>
    {
        options.ClusterId = "my-first-cluster";
        options.ServiceId = "MyOrleansService";
    })
    .UseAzureStorageClustering(
        options => options.ConnectionString = connectionString)
    .ConfigureApplicationParts(
        parts => parts.AddApplicationPart(
            typeof(IValueGrain).Assembly))
    .Build();

讓我們細分此範例中使用的步驟:

Orleans 叢集資訊

    .Configure<ClusterOptions>(options =>
    {
        options.ClusterId = "orleans-docker";
        options.ServiceId = "AspNetSampleApp";
    })

我們會在這裡設定兩件事:

  • ClusterOptions.ClusterId 設定為 "my-first-cluster":此為 Orleans 叢集的唯一識別碼。 使用此識別碼的所有用戶端和定址接收器都能夠彼此直接通訊。 例如,有些會選擇針對每個部署使用不同的 ClusterId
  • ClusterOptions.ServiceId 設定為 "AspNetSampleApp":這是應用程式的唯一識別碼,可供某些提供者使用 (例如持續性提供者)。 此識別碼在部署之間應保持穩定 (不會變更)。

叢集提供者

.UseAzureStorageClustering(
    options => options.ConfigureTableServiceClient(connectionString);
.UseAzureStorageClustering(
    options => options.ConnectionString = connectionString)

用戶端會使用此提供者來探索叢集中可用的所有閘道。 有數個提供者可供使用,在此範例中,我們會使用 Azure 資料表提供者。

如需詳細資訊,請參閱伺服器組態

應用程式組件

.ConfigureApplicationParts(
    parts => parts.AddApplicationPart(
        typeof(IValueGrain).Assembly))
        .WithReferences())

如需詳細資訊,請參閱伺服器組態