diff --git a/polaris-sync-registry-plugins/registry-consul/src/main/java/cn/polarismesh/polaris/sync/registry/plugins/consul/ConsulRegistryCenter.java b/polaris-sync-registry-plugins/registry-consul/src/main/java/cn/polarismesh/polaris/sync/registry/plugins/consul/ConsulRegistryCenter.java index 64fd7e3..fabd9c5 100644 --- a/polaris-sync-registry-plugins/registry-consul/src/main/java/cn/polarismesh/polaris/sync/registry/plugins/consul/ConsulRegistryCenter.java +++ b/polaris-sync-registry-plugins/registry-consul/src/main/java/cn/polarismesh/polaris/sync/registry/plugins/consul/ConsulRegistryCenter.java @@ -48,8 +48,10 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; @@ -199,20 +201,24 @@ private List convertConsulInstance(Service service, List filters = (null == group ? null : group.getMetadataMap()); + Set processedNodes = new HashSet<>(); for (HealthService healthService : instances) { - LOG.info("[Consul]convert instance {}", healthService); HealthService.Service instance = healthService.getService(); + HostAndPort hostAndPort = HostAndPort.build(instance.getAddress(), instance.getPort()); + if (processedNodes.contains(hostAndPort)) { + continue; + } + processedNodes.add(hostAndPort); Map metadata = instance.getMeta(); boolean matched = CommonUtils.matchMetadata(metadata, filters); - LOG.info("[Consul]convert instance {}, matched {}", healthService, matched); if (!matched) { continue; } Instance.Builder builder = Instance.newBuilder(); builder.setNamespace(ResponseUtils.toStringValue(service.getNamespace())); builder.setService(ResponseUtils.toStringValue(service.getService())); - builder.setHost(ResponseUtils.toStringValue(instance.getAddress())); - builder.setPort(ResponseUtils.toUInt32Value(instance.getPort())); + builder.setHost(ResponseUtils.toStringValue(hostAndPort.getHost())); + builder.setPort(ResponseUtils.toUInt32Value(hostAndPort.getPort())); if (!CollectionUtils.isEmpty(instance.getMeta())) { builder.putAllMetadata(instance.getMeta()); }