Browse Source

Some refactoring regarding ports.

pull/347/head
Sebastian Stehle 7 years ago
parent
commit
e2506c23f0
  1. 9
      src/Squidex/Config/Orleans/OrleansServices.cs
  2. 14
      src/Squidex/Config/ServiceExtensions.cs
  3. 6
      src/Squidex/appsettings.json

9
src/Squidex/Config/Orleans/OrleansServices.cs

@ -54,13 +54,14 @@ namespace Squidex.Config.Orleans
builder.AddMyParts(); builder.AddMyParts();
}); });
var gatewayPort = config.GetOptionalValue("orleans:gatewayPort", 40000);
var siloPort = config.GetOptionalValue("orleans:siloPort", 11111);
config.ConfigureByOption("orleans:clustering", new Options config.ConfigureByOption("orleans:clustering", new Options
{ {
["MongoDB"] = () => ["MongoDB"] = () =>
{ {
int siloPort = int.TryParse(config.GetRequiredValue("orleans:siloPort"), out siloPort) ? siloPort : 11111;
int gatewayPort = int.TryParse(config.GetRequiredValue("orleans:gatewayPort"), out gatewayPort) ? gatewayPort : 40000;
hostBuilder.ConfigureEndpoints(Dns.GetHostName(), siloPort, gatewayPort, listenOnAnyHostAddress: true); hostBuilder.ConfigureEndpoints(Dns.GetHostName(), siloPort, gatewayPort, listenOnAnyHostAddress: true);
var mongoConfiguration = config.GetRequiredValue("store:mongoDb:configuration"); var mongoConfiguration = config.GetRequiredValue("store:mongoDb:configuration");
@ -75,7 +76,7 @@ namespace Squidex.Config.Orleans
}, },
["Development"] = () => ["Development"] = () =>
{ {
hostBuilder.UseLocalhostClustering(gatewayPort: 40000, serviceId: Constants.OrleansClusterId, clusterId: Constants.OrleansClusterId); hostBuilder.UseLocalhostClustering(siloPort, gatewayPort, null, Constants.OrleansClusterId, Constants.OrleansClusterId);
hostBuilder.Configure<ClusterMembershipOptions>(options => options.ExpectedClusterSize = 1); hostBuilder.Configure<ClusterMembershipOptions>(options => options.ExpectedClusterSize = 1);
} }
}); });

14
src/Squidex/Config/ServiceExtensions.cs

@ -6,6 +6,7 @@
// ========================================================================== // ==========================================================================
using System; using System;
using System.Globalization;
using System.Linq; using System.Linq;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
@ -96,6 +97,19 @@ namespace Squidex.Config
return value; return value;
} }
public static int GetOptionalValue(this IConfiguration config, string path, int defaultValue)
{
var value = config.GetValue<string>(path);
var result = defaultValue;
if (string.IsNullOrWhiteSpace(value) || !int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out result))
{
result = defaultValue;
}
return result;
}
public static string GetRequiredValue(this IConfiguration config, string path) public static string GetRequiredValue(this IConfiguration config, string path)
{ {
var value = config.GetValue<string>(path); var value = config.GetValue<string>(path);

6
src/Squidex/appsettings.json

@ -179,10 +179,12 @@
*/ */
"clustering": "MongoDb", "clustering": "MongoDb",
/* /*
* The ports used to host the Orleans silo and the Gateway to connect to it * The port is used to share messages between all cluster members. Must be accessible within your cluster or network.
* optional: defaults to 11111 (silo) and 40000 (gateway) when not provided
*/ */
"siloPort": "11111", "siloPort": "11111",
/*
* The ports used by Orleans to connect to external clients. Not used.
*/
"gatewayPort": "40000" "gatewayPort": "40000"
}, },

Loading…
Cancel
Save