From d5419d69d0e499bb1abbd7cb308c64c49c0f5ffa Mon Sep 17 00:00:00 2001 From: Alex <97039406+chengyouling@users.noreply.github.com> Date: Mon, 13 Jan 2025 19:21:51 +0800 Subject: [PATCH] [#1411] support designated IPV4/IPV6 type configuration for register endpoint (#1414) --- .../DiscoveryBootstrapProperties.java | 44 ++++++++++++++----- .../discovery/MicroserviceHandler.java | 3 +- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/spring-cloud-huawei-service-engine/service-engine-common/src/main/java/com/huaweicloud/service/engine/common/configration/bootstrap/DiscoveryBootstrapProperties.java b/spring-cloud-huawei-service-engine/service-engine-common/src/main/java/com/huaweicloud/service/engine/common/configration/bootstrap/DiscoveryBootstrapProperties.java index 5da023200..c32847d50 100644 --- a/spring-cloud-huawei-service-engine/service-engine-common/src/main/java/com/huaweicloud/service/engine/common/configration/bootstrap/DiscoveryBootstrapProperties.java +++ b/spring-cloud-huawei-service-engine/service-engine-common/src/main/java/com/huaweicloud/service/engine/common/configration/bootstrap/DiscoveryBootstrapProperties.java @@ -74,6 +74,8 @@ public class DiscoveryBootstrapProperties { // enabled: true private boolean enableServicePolling = false; + private boolean preferIpv6Address = false; + public String getPublishAddress() { return publishAddress; } @@ -228,19 +230,37 @@ public void setOrder(int order) { this.order = order; } + public boolean isPreferIpv6Address() { + return preferIpv6Address; + } + + public void setPreferIpv6Address(boolean preferIpv6Address) { + this.preferIpv6Address = preferIpv6Address; + } + @Override public String toString() { - return "ServiceCombDiscoveryProperties{" + - "enabled=" + enabled + - ", watch=" + watch + - ", address='" + address + '\'' + - ", hostname='" + hostname + '\'' + - ", preferIpAddress=" + preferIpAddress + - ", healthCheck=" + healthCheck + - ", healthCheckInterval=" + healthCheckInterval + - ", autoDiscovery=" + autoDiscovery + - ", allowCrossApp=" + allowCrossApp + - ", dataCenter=" + datacenter + - '}'; + return "DiscoveryBootstrapProperties{" + + "enabled=" + enabled + + ", order=" + order + + ", watch=" + watch + + ", enableZoneAware=" + enableZoneAware + + ", address='" + address + '\'' + + ", hostname='" + hostname + '\'' + + ", preferIpAddress=" + preferIpAddress + + ", healthCheck=" + healthCheck + + ", healthCheckInterval=" + healthCheckInterval + + ", healthCheckRequestTimeout=" + healthCheckRequestTimeout + + ", pollInterval=" + pollInterval + + ", autoDiscovery=" + autoDiscovery + + ", waitTimeForShutDownInMillis=" + waitTimeForShutDownInMillis + + ", allowCrossApp=" + allowCrossApp + + ", publishAddress='" + publishAddress + '\'' + + ", ignoreSwaggerDifferent=" + ignoreSwaggerDifferent + + ", canOverwriteSwagger=" + canOverwriteSwagger + + ", datacenter=" + datacenter + + ", enableServicePolling=" + enableServicePolling + + ", preferIpv6Address='" + preferIpv6Address + '\'' + + '}'; } } diff --git a/spring-cloud-huawei-service-engine/service-engine-discovery/src/main/java/com/huaweicloud/servicecomb/discovery/discovery/MicroserviceHandler.java b/spring-cloud-huawei-service-engine/service-engine-discovery/src/main/java/com/huaweicloud/servicecomb/discovery/discovery/MicroserviceHandler.java index a612cbd1f..d8d03eebd 100644 --- a/spring-cloud-huawei-service-engine/service-engine-discovery/src/main/java/com/huaweicloud/servicecomb/discovery/discovery/MicroserviceHandler.java +++ b/spring-cloud-huawei-service-engine/service-engine-discovery/src/main/java/com/huaweicloud/servicecomb/discovery/discovery/MicroserviceHandler.java @@ -133,7 +133,8 @@ public static MicroserviceInstance createMicroserviceInstance( List endPoints = new ArrayList<>(); String address; if (StringUtils.isEmpty(discoveryBootstrapProperties.getPublishAddress())) { - address = NetUtils.getHostAddress(); + address = discoveryBootstrapProperties.isPreferIpv6Address() ? + NetUtils.getIpv6HostAddress() : NetUtils.getHostAddress(); } else { address = discoveryBootstrapProperties.getPublishAddress(); }