Skip to content

Commit

Permalink
fix:修复ServiceDiscovery在watch回调时没有正常过滤隔离实例 (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
chuntaojun authored Mar 1, 2024
1 parent e7c5589 commit d16ec7a
Showing 1 changed file with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,22 @@ private InnerServiceListener(String service) {
@Override
public void onEvent(ServiceChangeEvent event) {
String serviceName = event.getServiceKey().getService();
List<ServiceInstance> serviceInstances = event.getAllInstances()
.stream()
.map((Function<Instance, ServiceInstance>) 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<ServiceInstance> 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<ServiceInstancesChangedListener> listeners = serviceListeners.getOrDefault(service, Collections.emptySet());

Expand Down

0 comments on commit d16ec7a

Please sign in to comment.