private static IpPort genPublishIpPort(String schema, IpPort ipPort) {
String publicAddressSetting = DynamicPropertyFactory.getInstance()
.getStringProperty(PUBLISH_ADDRESS, "")
.get();
publicAddressSetting = publicAddressSetting.trim();
if (publicAddressSetting.isEmpty()) {
InetSocketAddress socketAddress = ipPort.getSocketAddress();
if (socketAddress.getAddress().isAnyLocalAddress()) {
String host = NetUtils.getHostAddress();
LOGGER.warn("address {}, auto select a host address to publish {}:{}, maybe not the correct one",
socketAddress,
host,
socketAddress.getPort());
return new IpPort(host, ipPort.getPort());
}
return ipPort;
}
if (publicAddressSetting.startsWith("{") && publicAddressSetting.endsWith("}")) {
publicAddressSetting = NetUtils
.ensureGetInterfaceAddress(
publicAddressSetting.substring(1, publicAddressSetting.length() - 1))
.getHostAddress();
}
String publishPortKey = PUBLISH_PORT.replace("{transport_name}", schema);
int publishPortSetting = DynamicPropertyFactory.getInstance()
.getIntProperty(publishPortKey, 0)
.get();
int publishPort = publishPortSetting == 0 ? ipPort.getPort() : publishPortSetting;
return new IpPort(publicAddressSetting, publishPort);
}