From e2506c23f0131820fe54fdbb43037d5131a6e604 Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Thu, 14 Feb 2019 10:42:22 +0100 Subject: [PATCH] Some refactoring regarding ports. --- src/Squidex/Config/Orleans/OrleansServices.cs | 9 +++++---- src/Squidex/Config/ServiceExtensions.cs | 14 ++++++++++++++ src/Squidex/appsettings.json | 6 ++++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/Squidex/Config/Orleans/OrleansServices.cs b/src/Squidex/Config/Orleans/OrleansServices.cs index 7ef2269c6..aed630ded 100644 --- a/src/Squidex/Config/Orleans/OrleansServices.cs +++ b/src/Squidex/Config/Orleans/OrleansServices.cs @@ -54,13 +54,14 @@ namespace Squidex.Config.Orleans builder.AddMyParts(); }); + var gatewayPort = config.GetOptionalValue("orleans:gatewayPort", 40000); + + var siloPort = config.GetOptionalValue("orleans:siloPort", 11111); + config.ConfigureByOption("orleans:clustering", new Options { ["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); var mongoConfiguration = config.GetRequiredValue("store:mongoDb:configuration"); @@ -75,7 +76,7 @@ namespace Squidex.Config.Orleans }, ["Development"] = () => { - hostBuilder.UseLocalhostClustering(gatewayPort: 40000, serviceId: Constants.OrleansClusterId, clusterId: Constants.OrleansClusterId); + hostBuilder.UseLocalhostClustering(siloPort, gatewayPort, null, Constants.OrleansClusterId, Constants.OrleansClusterId); hostBuilder.Configure(options => options.ExpectedClusterSize = 1); } }); diff --git a/src/Squidex/Config/ServiceExtensions.cs b/src/Squidex/Config/ServiceExtensions.cs index 72edccd17..8d185bf60 100644 --- a/src/Squidex/Config/ServiceExtensions.cs +++ b/src/Squidex/Config/ServiceExtensions.cs @@ -6,6 +6,7 @@ // ========================================================================== using System; +using System.Globalization; using System.Linq; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -96,6 +97,19 @@ namespace Squidex.Config return value; } + public static int GetOptionalValue(this IConfiguration config, string path, int defaultValue) + { + var value = config.GetValue(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) { var value = config.GetValue(path); diff --git a/src/Squidex/appsettings.json b/src/Squidex/appsettings.json index 0f4282395..d3275b9ac 100644 --- a/src/Squidex/appsettings.json +++ b/src/Squidex/appsettings.json @@ -179,10 +179,12 @@ */ "clustering": "MongoDb", /* - * The ports used to host the Orleans silo and the Gateway to connect to it - * optional: defaults to 11111 (silo) and 40000 (gateway) when not provided + * The port is used to share messages between all cluster members. Must be accessible within your cluster or network. */ "siloPort": "11111", + /* + * The ports used by Orleans to connect to external clients. Not used. + */ "gatewayPort": "40000" },