Skip to content

Commit

Permalink
An improved method for obtaining ip address and port number from cont…
Browse files Browse the repository at this point in the history
…ainers
  • Loading branch information
goodjava committed Apr 26, 2021
1 parent 26158ad commit d03704b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,24 @@ public static String getConfig(String key) {
AssertUtil.notNull(key, "key cannot be null");
return props.get(key);
}

/**
* Get config value of the specific key.
*
* @param key config key
* @param envVariableKey Get the value of the environment variable with the given key
* @return the config value.
*/
public static String getConfig(String key, boolean envVariableKey) {
AssertUtil.notNull(key, "key cannot be null");
if (envVariableKey) {
String value = System.getenv(key);
if (StringUtil.isNotEmpty(value)) {
return value;
}
}
return getConfig(key);
}

public static void setConfig(String key, String value) {
AssertUtil.notNull(key, "key cannot be null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public static String getPort() {
if (runtimePort > 0) {
return String.valueOf(runtimePort);
}
return SentinelConfig.getConfig(SERVER_PORT);
return SentinelConfig.getConfig(SERVER_PORT, true);
}

/**
Expand All @@ -159,7 +159,7 @@ public static void setRuntimePort(int port) {
* @return the local ip.
*/
public static String getHeartbeatClientIp() {
String ip = SentinelConfig.getConfig(HEARTBEAT_CLIENT_IP);
String ip = SentinelConfig.getConfig(HEARTBEAT_CLIENT_IP, true);
if (StringUtil.isBlank(ip)) {
ip = HostNameUtil.getIp();
}
Expand Down

0 comments on commit d03704b

Please sign in to comment.