Orleans 2.0 官方文档 —— 5.5.5 集群和客户端 -> 配置指南 -> 典型的配置

典型的配置

以下是可用于开发和生产部署的典型的配置示例。

本地开发

请参阅本地开发配置

使用Azure进行可靠的生产部署

对于使用Azure进行可靠的生产部署,您需要使用Azure表用于集群的成员身份管理。此配置是部署到内部部署服务器、容器或Azure虚拟机实例的典型配置。

DataConnection字符串的格式是 "DefaultEndpointsProtocol=https;AccountName=;AccountKey="

silo的配置:

// TODO replace with your connection string
const string connectionString = "YOUR_CONNECTION_STRING_HERE";
var silo = new SiloHostBuilder()
    .Configure(options =>
    {
        options.ClusterId = "Cluster42";
        options.ServiceId = "MyAwesomeService";
    })
    .UseAzureStorageClustering(options => options.ConnectionString = connectionString)
    .ConfigureEndpoints(siloPort: 11111, gatewayPort: 30000)
    .ConfigureLogging(builder => builder.SetMinimumLevel(LogLevel.Warning).AddConsole())
    .Build();

客户端配置:

// TODO replace with your connection string
const string connectionString = "YOUR_CONNECTION_STRING_HERE";
var client = new ClientBuilder()
    .Configure(options =>
    {
        options.ClusterId = "Cluster42";
        options.ServiceId = "MyAwesomeService";
    })
    .UseAzureStorageClustering(options => options.ConnectionString = connectionString)
    .ConfigureLogging(builder => builder.SetMinimumLevel(LogLevel.Warning).AddConsole())
    .Build();

使用SQL Server进行可靠的生产部署

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

silo的配置:

// TODO replace with your connection string
const string connectionString = "YOUR_CONNECTION_STRING_HERE";
var silo = new SiloHostBuilder()
    .Configure(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();

客户端配置:

// TODO replace with your connection string
const string connectionString = "YOUR_CONNECTION_STRING_HERE";
var client = new ClientBuilder()
    .Configure(options =>
    {
        options.ClusterId = "Cluster42";
        options.ServiceId = "MyAwesomeService";
    })
    .UseAdoNetClustering(options =>
    { 
      options.ConnectionString = connectionString;
      options.Invariant = "System.Data.SqlClient";
    })
    .ConfigureLogging(builder => builder.SetMinimumLevel(LogLevel.Warning).AddConsole())
    .Build();

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

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

在silo上:

var primarySiloEndpoint = new IPEndpoint(PRIMARY_SILO_IP_ADDRESS, 11111);
var silo = new SiloHostBuilder()
  .UseDevelopmentClustering(primarySiloEndpoint)
  .Configure(options =>
  {
    options.ClusterId = "Cluster42";
    options.ServiceId = "MyAwesomeService";
  })
  .ConfigureEndpoints(siloPort: 11111, gatewayPort: 30000)
  .ConfigureLogging(logging => logging.AddConsole())
  .Build();

在客户端:

var gateways = new IPEndPoint[]
{
    new IPEndPoint(PRIMARY_SILO_IP_ADDRESS, 30000),
    new IPEndPoint(OTHER_SILO__IP_ADDRESS_1, 30000),
    [...]
    new IPEndPoint(OTHER_SILO__IP_ADDRESS_N, 30000),
};
var client = new ClientBuilder()
    .UseStaticClustering(gateways)
    .Configure(options =>
    {
        options.ClusterId = "dev";
        options.ServiceId = "AdventureApp";
    })
    .ConfigureLogging(logging => logging.AddConsole())
    .Build();

你可能感兴趣的:(Orleans)