mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
To filter null , disable or unhealthy Nacos instances
This commit is contained in:
parent
7580d8b1cd
commit
89ad537f66
@ -65,6 +65,9 @@ public class NacosDiscoveryClient implements DiscoveryClient {
|
||||
|
||||
public static ServiceInstance hostToServiceInstance(Instance instance,
|
||||
String serviceId) {
|
||||
if (instance == null || !instance.isEnabled() || !instance.isHealthy()) {
|
||||
return null;
|
||||
}
|
||||
NacosServiceInstance nacosServiceInstance = new NacosServiceInstance();
|
||||
nacosServiceInstance.setHost(instance.getIp());
|
||||
nacosServiceInstance.setPort(instance.getPort());
|
||||
@ -89,7 +92,10 @@ public class NacosDiscoveryClient implements DiscoveryClient {
|
||||
List<Instance> instances, String serviceId) {
|
||||
List<ServiceInstance> result = new ArrayList<>(instances.size());
|
||||
for (Instance instance : instances) {
|
||||
result.add(hostToServiceInstance(instance, serviceId));
|
||||
ServiceInstance serviceInstance = hostToServiceInstance(instance, serviceId);
|
||||
if (serviceInstance != null) {
|
||||
result.add(serviceInstance);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user