@@ -14,6 +14,17 @@ public static class LighthouseHostFactory
14
14
{
15
15
public static ActorSystem LaunchLighthouse ( string ipAddress = null , int ? specifiedPort = null , string systemName = null )
16
16
{
17
+ systemName = systemName ?? Environment . GetEnvironmentVariable ( "ACTORSYSTEM" ) ? . Trim ( ) ;
18
+ ipAddress = ipAddress ?? Environment . GetEnvironmentVariable ( "CLUSTER_IP" ) ? . Trim ( ) ;
19
+ if ( specifiedPort == null )
20
+ {
21
+ var envPort = Environment . GetEnvironmentVariable ( "CLUSTER_PORT" ) ? . Trim ( ) ;
22
+ if ( ! string . IsNullOrEmpty ( envPort ) && int . TryParse ( envPort , out var actualPort ) )
23
+ {
24
+ specifiedPort = actualPort ;
25
+ }
26
+ }
27
+
17
28
var clusterConfig = ConfigurationFactory . ParseString ( File . ReadAllText ( "akka.hocon" ) ) ;
18
29
19
30
var lighthouseConfig = clusterConfig . GetConfig ( "lighthouse" ) ;
@@ -23,9 +34,13 @@ public static ActorSystem LaunchLighthouse(string ipAddress = null, int? specifi
23
34
}
24
35
25
36
var remoteConfig = clusterConfig . GetConfig ( "akka.remote" ) ;
26
- ipAddress = ipAddress ??
27
- remoteConfig . GetString ( "dot-netty.tcp.public-hostname" ) ??
28
- "127.0.0.1" ; //localhost as a final default
37
+
38
+ if ( string . IsNullOrEmpty ( ipAddress ) )
39
+ {
40
+ ipAddress = remoteConfig . GetString ( "dot-netty.tcp.public-hostname" ) ??
41
+ "127.0.0.1" ; //localhost as a final default
42
+ }
43
+
29
44
int port = specifiedPort ?? remoteConfig . GetInt ( "dot-netty.tcp.port" ) ;
30
45
31
46
if ( port == 0 ) throw new ConfigurationException ( "Need to specify an explicit port for Lighthouse. Found an undefined port or a port value of 0 in App.config." ) ;
@@ -40,7 +55,19 @@ public static ActorSystem LaunchLighthouse(string ipAddress = null, int? specifi
40
55
selfAddress = new Address ( "akka.tcp" , systemName , ipAddress . Trim ( ) , port ) . ToString ( ) ;
41
56
Console . WriteLine ( "[Lighthouse] Parse successful." ) ;
42
57
58
+ var clusterSeeds = Environment . GetEnvironmentVariable ( "CLUSTER_SEEDS" ) ? . Trim ( ) ;
59
+
43
60
var seeds = clusterConfig . GetStringList ( "akka.cluster.seed-nodes" ) ;
61
+ if ( ! string . IsNullOrEmpty ( clusterSeeds ) )
62
+ {
63
+ var tempSeeds = clusterSeeds . Trim ( '[' , ']' ) . Split ( ',' ) ;
64
+ if ( tempSeeds . Any ( ) )
65
+ {
66
+ seeds = tempSeeds ;
67
+ }
68
+ }
69
+
70
+
44
71
if ( ! seeds . Contains ( selfAddress ) )
45
72
{
46
73
seeds . Add ( selfAddress ) ;
0 commit comments