From d16ec7a7a7b39e06b86198aecb884ee9fb002e0a Mon Sep 17 00:00:00 2001 From: liaochuntao Date: Fri, 1 Mar 2024 15:40:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8DServiceDiscovery=E5=9C=A8?= =?UTF-8?q?watch=E5=9B=9E=E8=B0=83=E6=97=B6=E6=B2=A1=E6=9C=89=E6=AD=A3?= =?UTF-8?q?=E5=B8=B8=E8=BF=87=E6=BB=A4=E9=9A=94=E7=A6=BB=E5=AE=9E=E4=BE=8B?= =?UTF-8?q?=20(#55)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../registry/PolarisServiceDiscovery.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/java/com/tencent/polaris/dubbo/registry/PolarisServiceDiscovery.java b/dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/java/com/tencent/polaris/dubbo/registry/PolarisServiceDiscovery.java index 8c483e6..3d70de7 100644 --- a/dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/java/com/tencent/polaris/dubbo/registry/PolarisServiceDiscovery.java +++ b/dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/java/com/tencent/polaris/dubbo/registry/PolarisServiceDiscovery.java @@ -188,20 +188,22 @@ private InnerServiceListener(String service) { @Override public void onEvent(ServiceChangeEvent event) { String serviceName = event.getServiceKey().getService(); - List serviceInstances = event.getAllInstances() - .stream() - .map((Function) instance -> { - DefaultServiceInstance serviceInstance = - new DefaultServiceInstance( - instance.getService(), - instance.getHost(), instance.getPort(), - ScopeModelUtil.getApplicationModel(registryURL.getScopeModel())); - serviceInstance.setMetadata(instance.getMetadata()); - serviceInstance.setEnabled(!instance.isIsolated()); - serviceInstance.setHealthy(instance.isHealthy()); - return serviceInstance; - }) - .collect(Collectors.toList()); + Instance[] instances = operator.getAvailableInstances(serviceName, true); + if (Objects.isNull(instances) || instances.length == 0) { + return; + } + List serviceInstances = new ArrayList<>(instances.length); + for (Instance instance : instances) { + DefaultServiceInstance serviceInstance = + new DefaultServiceInstance( + instance.getService(), + instance.getHost(), instance.getPort(), + ScopeModelUtil.getApplicationModel(registryURL.getScopeModel())); + serviceInstance.setMetadata(instance.getMetadata()); + serviceInstance.setEnabled(!instance.isIsolated()); + serviceInstance.setHealthy(instance.isHealthy()); + serviceInstances.add(serviceInstance); + } Set listeners = serviceListeners.getOrDefault(service, Collections.emptySet());