次の方法で共有


クライアントの構成

サイロのクラスターに接続してグレインに要求を送信するためのクライアントは、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";
    })

ここでは、次の 2 つの設定を行います。

  • ClusterOptions.ClusterId"my-first-cluster" に設定: これは、Orleans クラスターに一意の ID です。 この ID を使用するすべてのクライアントとサイロは、相互に直接通信できます。 たとえば、デプロイごとに異なる ClusterId を使用する場合があります。
  • ClusterOptions.ServiceId"AspNetSampleApp" に: これは、一部のプロバイダー (永続化プロバイダーなど) によって使用されるアプリケーションの一意の ID です。 この ID は、デプロイ全体で安定している (変更されない) 必要があります。

クラスタリング プロバイダー

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

クライアントは、このプロバイダーを使用して、クラスターで使用可能なすべてのゲートウェイを検出します。 いくつかのプロバイダーを使用できます。このサンプルでは、Azure Table プロバイダーを使用します。

詳しくは、「サーバー構成」をご覧ください。

アプリケーション パーツ

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

詳しくは、「サーバー構成」をご覧ください。