diff --git a/src/Managing.Api/README-ORLEANS-TROUBLESHOOTING.md b/src/Managing.Api/README-ORLEANS-TROUBLESHOOTING.md index f249da3..518cfc1 100644 --- a/src/Managing.Api/README-ORLEANS-TROUBLESHOOTING.md +++ b/src/Managing.Api/README-ORLEANS-TROUBLESHOOTING.md @@ -56,6 +56,7 @@ In `appsettings.Production.json`: #### Environment Variables - `RUN_ORLEANS_GRAINS`: Enable/disable Orleans grains (true/false) - `DISABLE_ORLEANS_CLUSTERING`: Force localhost clustering (true/false) +- `ORLEANS_ADVERTISED_IP`: Set specific IP address for Orleans clustering (e.g., "192.168.1.100") - `ASPNETCORE_ENVIRONMENT`: Set environment (Production/Development/etc.) ### 3. Network Configuration Improvements diff --git a/src/Managing.Bootstrap/ApiBootstrap.cs b/src/Managing.Bootstrap/ApiBootstrap.cs index f17a76e..ad30603 100644 --- a/src/Managing.Bootstrap/ApiBootstrap.cs +++ b/src/Managing.Bootstrap/ApiBootstrap.cs @@ -124,22 +124,28 @@ public static class ApiBootstrap } // Configure networking for better silo communication + var advertisedIP = Environment.GetEnvironmentVariable("ORLEANS_ADVERTISED_IP"); + IPAddress advertisedIPAddress = null; + + if (!string.IsNullOrEmpty(advertisedIP) && IPAddress.TryParse(advertisedIP, out var ipAddress)) + { + advertisedIPAddress = ipAddress; + } + else if (disableOrleansClustering) + { + advertisedIPAddress = IPAddress.Loopback; + } + + if (advertisedIPAddress != null) + { + siloBuilder.ConfigureEndpoints(advertisedIPAddress, 11111, 30000); + } + else + { + siloBuilder.ConfigureEndpoints(siloPort: 11111, gatewayPort: 30000); + } + siloBuilder - .ConfigureEndpoints(siloPort: 11111, gatewayPort: 30000, advertisedIP: null, listenOnAnyHostAddress: true) - .Configure(options => - { - // Set the advertised IP address for clustering - var advertisedIP = Environment.GetEnvironmentVariable("ORLEANS_ADVERTISED_IP"); - if (!string.IsNullOrEmpty(advertisedIP) && IPAddress.TryParse(advertisedIP, out var ipAddress)) - { - options.AdvertisedIPAddress = ipAddress; - } - else - { - // Fallback to localhost for single-node deployments or when clustering is disabled - options.AdvertisedIPAddress = disableOrleansClustering ? IPAddress.Loopback : IPAddress.Any; - } - }) .Configure(options => { // Configure cluster options with unique identifiers