下面是可用于开发和生产部署的典型配置示例。
本地开发
有关详细信息,请参阅 本地开发配置。
使用 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>"
接收器配置:
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 连接字符串。
接收器配置:
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 表的依赖。 只需将其中一个节点指定为主节点。
在孤岛上:
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();