Teilen über


Typische Konfigurationen

Im Folgenden finden Sie Beispiele für typische Konfigurationen, die für Entwicklungs- und Produktionsbereitstellungen genutzt werden können.

Lokale Entwicklung

Weitere Informationen finden Sie unter Konfiguration für die lokale Entwicklung.

Zuverlässige Produktionsbereitstellung mit Azure

Für eine zuverlässige Produktionsbereitstellung unter Verwendung von Azure müssen Sie die Azure Table Storage-Option für die Clustermitgliedschaft verwenden. Diese Konfiguration ist typisch für Bereitstellungen auf lokalen Servern, in Containern oder auf Azure-VM-Instanzen.

Das Format der DataConnection-Zeichenfolge ist eine durch ; getrennte Liste mit Key=Value-Paaren. Die folgenden Optionen werden unterstützt:

Schlüssel Wert
DefaultEndpointsProtocol https
AccountName <Azure storage account>
AccountKey <Azure table storage account key>

Im Folgenden sehen Sie ein Beispiel einer DataConnection-Zeichenfolge für Azure Table Storage:

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

Silokonfiguration:

const string connectionString = "YOUR_CONNECTION_STRING_HERE";
var silo = new HostBuilder()
    .UseOrleans(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();

Clientkonfiguration:

const string connectionString = "YOUR_CONNECTION_STRING_HERE";
var client = new ClientBuilder()
    .Configure<ClusterOptions>(options =>
    {
        options.ClusterId = "Cluster42";
        options.ServiceId = "MyAwesomeService";
    })
    .UseAzureStorageClustering(
        options => options.ConfigureTableServiceClient(connectionString))
    .ConfigureLogging(builder => builder.SetMinimumLevel(LogLevel.Warning).AddConsole())
    .Build();

Zuverlässige Produktionsbereitstellung mit SQL Server

Für eine zuverlässige Produktionsbereitstellung unter Verwendung von SQL Server muss eine SQL Server-Verbindungszeichenfolge angegeben werden.

Silokonfiguration:

const string connectionString = "YOUR_CONNECTION_STRING_HERE";
var silo = new HostBuilder()
    .UseOrleans(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();

Clientkonfiguration:

const string connectionString = "YOUR_CONNECTION_STRING_HERE";
var client = new ClientBuilder()
    .Configure<ClusterOptions>(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();

Unzuverlässige Bereitstellung auf einem Cluster mit dedizierten Servern

Für Tests in einem Cluster mit dedizierten Servern, bei denen die Zuverlässigkeit keine Rolle spielt, können Sie MembershipTableGrain nutzen und die Abhängigkeit von Azure Table Storage vermeiden. Sie müssen lediglich einen der Knoten als primär festlegen.

Für die Silos:

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

Für die Clients:

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),
};
var client = new ClientBuilder()
    .UseStaticClustering(gateways)
    .Configure<ClusterOptions>(options =>
    {
        options.ClusterId = "Cluster42";
        options.ServiceId = "MyAwesomeService";
    })
    .ConfigureLogging(logging => logging.AddConsole())
    .Build();