Skip to content

Commit d16ec7a

Browse files
authored
fix:修复ServiceDiscovery在watch回调时没有正常过滤隔离实例 (#55)
1 parent e7c5589 commit d16ec7a

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

dubbo/dubbo-plugins/dubbo-registry-polaris/src/main/java/com/tencent/polaris/dubbo/registry/PolarisServiceDiscovery.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -188,20 +188,22 @@ private InnerServiceListener(String service) {
188188
@Override
189189
public void onEvent(ServiceChangeEvent event) {
190190
String serviceName = event.getServiceKey().getService();
191-
List<ServiceInstance> serviceInstances = event.getAllInstances()
192-
.stream()
193-
.map((Function<Instance, ServiceInstance>) instance -> {
194-
DefaultServiceInstance serviceInstance =
195-
new DefaultServiceInstance(
196-
instance.getService(),
197-
instance.getHost(), instance.getPort(),
198-
ScopeModelUtil.getApplicationModel(registryURL.getScopeModel()));
199-
serviceInstance.setMetadata(instance.getMetadata());
200-
serviceInstance.setEnabled(!instance.isIsolated());
201-
serviceInstance.setHealthy(instance.isHealthy());
202-
return serviceInstance;
203-
})
204-
.collect(Collectors.toList());
191+
Instance[] instances = operator.getAvailableInstances(serviceName, true);
192+
if (Objects.isNull(instances) || instances.length == 0) {
193+
return;
194+
}
195+
List<ServiceInstance> serviceInstances = new ArrayList<>(instances.length);
196+
for (Instance instance : instances) {
197+
DefaultServiceInstance serviceInstance =
198+
new DefaultServiceInstance(
199+
instance.getService(),
200+
instance.getHost(), instance.getPort(),
201+
ScopeModelUtil.getApplicationModel(registryURL.getScopeModel()));
202+
serviceInstance.setMetadata(instance.getMetadata());
203+
serviceInstance.setEnabled(!instance.isIsolated());
204+
serviceInstance.setHealthy(instance.isHealthy());
205+
serviceInstances.add(serviceInstance);
206+
}
205207

206208
Set<ServiceInstancesChangedListener> listeners = serviceListeners.getOrDefault(service, Collections.emptySet());
207209

0 commit comments

Comments
 (0)