1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

update nacos discovery logic, support both health and enabled

This commit is contained in:
flystar32 2018-12-04 15:02:26 +08:00
parent 4f2eb7487d
commit eeba7e6aa6
3 changed files with 14 additions and 17 deletions

View File

@ -48,7 +48,7 @@ public class NacosDiscoveryClient implements DiscoveryClient {
public List<ServiceInstance> getInstances(String serviceId) {
try {
List<Instance> instances = discoveryProperties.namingServiceInstance()
.getAllInstances(serviceId);
.selectInstances(serviceId, true);
return hostToServiceInstanceList(instances, serviceId);
}
catch (Exception e) {
@ -77,10 +77,8 @@ public class NacosDiscoveryClient implements DiscoveryClient {
List<Instance> instances, String serviceId) {
List<ServiceInstance> result = new ArrayList<ServiceInstance>(instances.size());
for (Instance instance : instances) {
if (instance.isHealthy()) {
result.add(hostToServiceInstance(instance, serviceId));
}
}
return result;
}

View File

@ -323,7 +323,8 @@ public class NacosDiscoveryProperties {
+ ", metadata=" + metadata + ", registerEnabled=" + registerEnabled
+ ", ip='" + ip + '\'' + ", networkInterface='" + networkInterface + '\''
+ ", port=" + port + ", secure=" + secure + ", accessKey='" + accessKey
+ ", namingLoadCacheAtStart=" + namingLoadCacheAtStart + '\'' + ", secretKey='" + secretKey + '\'' + '}';
+ ", namingLoadCacheAtStart=" + namingLoadCacheAtStart + '\''
+ ", secretKey='" + secretKey + '\'' + '}';
}
public void overrideFromEnv(Environment env) {

View File

@ -57,7 +57,7 @@ public class NacosServerList extends AbstractServerList<NacosServer> {
private List<NacosServer> getServers() {
try {
List<Instance> instances = discoveryProperties.namingServiceInstance()
.getAllInstances(serviceId);
.selectInstances(serviceId, true);
return instancesToServerList(instances);
}
catch (Exception e) {
@ -70,10 +70,8 @@ public class NacosServerList extends AbstractServerList<NacosServer> {
private List<NacosServer> instancesToServerList(List<Instance> instances) {
List<NacosServer> result = new ArrayList<>(instances.size());
for (Instance instance : instances) {
if (instance.isHealthy()) {
result.add(new NacosServer(instance));
}
}
return result;
}