Edit

Share via


Client configuration

Configure a client for connecting to a cluster of silos and sending requests to grains programmatically via an IHostBuilder and several supplemental option classes. Like silo options, client option classes follow the Options pattern in .NET.

Configure a client for connecting to a cluster of silos and sending requests to grains programmatically via an ClientBuilder and several supplemental option classes. Like silo options, client option classes follow the Options pattern in .NET.

Tip

If you just want to start a local silo and a local client for development purposes, see Local development configuration.

Add the Microsoft.Orleans.Clustering.AzureStorage NuGet package to your client project.

There are several key aspects of client configuration:

  • Orleans clustering information
  • Clustering provider
  • Application parts

Example of a client configuration:

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();

Let's break down the steps used in this sample:

Orleans clustering information

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

Here, we set two things:

  • The ClusterOptions.ClusterId to "my-first-cluster": This is a unique ID for the Orleans cluster. All clients and silos using this ID can directly talk to each other. Some might choose to use a different ClusterId for each deployment, for example.
  • The ClusterOptions.ServiceId to "AspNetSampleApp": This is a unique ID for your application, used by some providers (e.g., persistence providers). This ID should remain stable across deployments.

Clustering provider

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

The client discovers all available gateways in the cluster using this provider. Several providers are available; here, we use the Azure Table provider.

For more information, see Server configuration.

Application parts

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

For more information, see Server configuration.