典型配置

下面是可在开发和生产部署中使用的典型配置的示例。

本地开发

有关详细信息,请参阅本地开发配置

使用 Azure 的可靠生产部署

对于使用 Azure 的可靠生产部署,你需要将 Azure 表选项用于群集成员身份。 此配置是本地服务器、容器或 Azure 虚拟机实例的典型部署。

DataConnection 字符串的格式是 ; 分隔的 Key=Value 对列表。 可以使用以下选项:

密钥
DefaultEndpointsProtocol https
AccountName <Azure storage account>
AccountKey <Azure table storage account key>

下面是适用于 Azure 表存储的 DataConnection 字符串示例:

"DefaultEndpointsProtocol=https;AccountName=<Azure storage account>;AccountKey=<Azure table storage account key>"

Silo 配置:

const string connectionString = "YOUR_CONNECTION_STRING_HERE";
var silo = new HostBuilder()
    .UseOrleans(builder =>
    {
        builder.Configure<ClusterOptions>(options =>
        {
            options.ClusterId = "Cluster42";
            options.ServiceId = "MyAwesomeService";
        })
        .UseAzureStorageClustering(
            options => options.ConfigureTableServiceClient(connectionString))
        .ConfigureEndpoints(siloPort: 11_111, gatewayPort: 30_000)
        .ConfigureLogging(builder => builder.SetMinimumLevel(LogLevel.Warning).AddConsole())
    })
    .Build();

客户端配置:

const string connectionString = "YOUR_CONNECTION_STRING_HERE";

using var host = Host.CreateDefaultBuilder(args)
    .UseOrleansClient(clientBuilder =>
        clientBuilder.Configure<ClusterOptions>(options =>
        {
            options.ClusterId = "Cluster42";
            options.ServiceId = "MyAwesomeService";
        })
        .UseAzureStorageClustering(
            options => options.ConfigureTableServiceClient(connectionString)))
    .Build();

使用 SQL Server 的可靠生产部署

对于使用 SQL Server 的可靠生产部署,需要提供 SQL Server 连接字符串。

Silo 配置:

const string connectionString = "YOUR_CONNECTION_STRING_HERE";
var silo = new HostBuilder()
    .UseOrleans(builder =>
    {
        builder.Configure<ClusterOptions>(options =>
        {
            options.ClusterId = "Cluster42";
            options.ServiceId = "MyAwesomeService";
        })
        .UseAdoNetClustering(options =>
        {
          options.ConnectionString = connectionString;
          options.Invariant = "System.Data.SqlClient";
        })
        .ConfigureEndpoints(siloPort: 11111, gatewayPort: 30000)
        .ConfigureLogging(builder => builder.SetMinimumLevel(LogLevel.Warning).AddConsole())
    })
    .Build();

客户端配置:

const string connectionString = "YOUR_CONNECTION_STRING_HERE";

using var host = Host.CreateDefaultBuilder(args)
    .UseOrleansClient(clientBuilder =>
        clientBuilder.Configure<ClusterOptions>(options =>
        {
            options.ClusterId = "Cluster42";
            options.ServiceId = "MyAwesomeService";
        })
        .UseAdoNetClustering(options =>
        {
          options.ConnectionString = connectionString;
          options.Invariant = "System.Data.SqlClient";
        }))
    .Build();

专用服务器群集上的不可靠部署

对于在专用服务器集群上进行测试,当可靠性不是需要顾虑的问题时,你可以利用 MembershipTableGrain 并避免依赖 Azure表。 你只需将其中一个节点指定为主节点。

在 silo 上:

var primarySiloEndpoint = new IPEndpoint(PRIMARY_SILO_IP_ADDRESS, 11_111);
var silo = new HostBuilder()
    .UseOrleans(builder =>
    {
        builder
            .UseDevelopmentClustering(primarySiloEndpoint)
            .Configure<ClusterOptions>(options =>
            {
                options.ClusterId = "Cluster42";
                options.ServiceId = "MyAwesomeService";
            })
            .ConfigureEndpoints(siloPort: 11_111, gatewayPort: 30_000)
            .ConfigureLogging(logging => logging.AddConsole())
    })
    .Build();

在客户端上:

var gateways = new IPEndPoint[]
{
    new IPEndPoint(PRIMARY_SILO_IP_ADDRESS, 30_000),
    new IPEndPoint(OTHER_SILO__IP_ADDRESS_1, 30_000),
    // ...
    new IPEndPoint(OTHER_SILO__IP_ADDRESS_N, 30_000),
};

using var host = Host.CreateDefaultBuilder(args)
    .UseOrleansClient(clientBuilder =>
        clientBuilder.UseStaticClustering(gateways)
            .Configure<ClusterOptions>(options =>
            {
                options.ClusterId = "Cluster42";
                options.ServiceId = "MyAwesomeService";
            }))
    .Build();