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:
parent
4f2eb7487d
commit
eeba7e6aa6
@ -48,7 +48,7 @@ public class NacosDiscoveryClient implements DiscoveryClient {
|
|||||||
public List<ServiceInstance> getInstances(String serviceId) {
|
public List<ServiceInstance> getInstances(String serviceId) {
|
||||||
try {
|
try {
|
||||||
List<Instance> instances = discoveryProperties.namingServiceInstance()
|
List<Instance> instances = discoveryProperties.namingServiceInstance()
|
||||||
.getAllInstances(serviceId);
|
.selectInstances(serviceId, true);
|
||||||
return hostToServiceInstanceList(instances, serviceId);
|
return hostToServiceInstanceList(instances, serviceId);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
@ -77,10 +77,8 @@ public class NacosDiscoveryClient implements DiscoveryClient {
|
|||||||
List<Instance> instances, String serviceId) {
|
List<Instance> instances, String serviceId) {
|
||||||
List<ServiceInstance> result = new ArrayList<ServiceInstance>(instances.size());
|
List<ServiceInstance> result = new ArrayList<ServiceInstance>(instances.size());
|
||||||
for (Instance instance : instances) {
|
for (Instance instance : instances) {
|
||||||
if (instance.isHealthy()) {
|
|
||||||
result.add(hostToServiceInstance(instance, serviceId));
|
result.add(hostToServiceInstance(instance, serviceId));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,7 +323,8 @@ public class NacosDiscoveryProperties {
|
|||||||
+ ", metadata=" + metadata + ", registerEnabled=" + registerEnabled
|
+ ", metadata=" + metadata + ", registerEnabled=" + registerEnabled
|
||||||
+ ", ip='" + ip + '\'' + ", networkInterface='" + networkInterface + '\''
|
+ ", ip='" + ip + '\'' + ", networkInterface='" + networkInterface + '\''
|
||||||
+ ", port=" + port + ", secure=" + secure + ", accessKey='" + accessKey
|
+ ", port=" + port + ", secure=" + secure + ", accessKey='" + accessKey
|
||||||
+ ", namingLoadCacheAtStart=" + namingLoadCacheAtStart + '\'' + ", secretKey='" + secretKey + '\'' + '}';
|
+ ", namingLoadCacheAtStart=" + namingLoadCacheAtStart + '\''
|
||||||
|
+ ", secretKey='" + secretKey + '\'' + '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
public void overrideFromEnv(Environment env) {
|
public void overrideFromEnv(Environment env) {
|
||||||
@ -372,7 +373,7 @@ public class NacosDiscoveryProperties {
|
|||||||
properties.put(ACCESS_KEY, accessKey);
|
properties.put(ACCESS_KEY, accessKey);
|
||||||
properties.put(SECRET_KEY, secretKey);
|
properties.put(SECRET_KEY, secretKey);
|
||||||
properties.put(CLUSTER_NAME, clusterName);
|
properties.put(CLUSTER_NAME, clusterName);
|
||||||
properties.put(NAMING_LOAD_CACHE_AT_START,namingLoadCacheAtStart);
|
properties.put(NAMING_LOAD_CACHE_AT_START, namingLoadCacheAtStart);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
namingService = NacosFactory.createNamingService(properties);
|
namingService = NacosFactory.createNamingService(properties);
|
||||||
|
@ -57,7 +57,7 @@ public class NacosServerList extends AbstractServerList<NacosServer> {
|
|||||||
private List<NacosServer> getServers() {
|
private List<NacosServer> getServers() {
|
||||||
try {
|
try {
|
||||||
List<Instance> instances = discoveryProperties.namingServiceInstance()
|
List<Instance> instances = discoveryProperties.namingServiceInstance()
|
||||||
.getAllInstances(serviceId);
|
.selectInstances(serviceId, true);
|
||||||
return instancesToServerList(instances);
|
return instancesToServerList(instances);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
@ -70,10 +70,8 @@ public class NacosServerList extends AbstractServerList<NacosServer> {
|
|||||||
private List<NacosServer> instancesToServerList(List<Instance> instances) {
|
private List<NacosServer> instancesToServerList(List<Instance> instances) {
|
||||||
List<NacosServer> result = new ArrayList<>(instances.size());
|
List<NacosServer> result = new ArrayList<>(instances.size());
|
||||||
for (Instance instance : instances) {
|
for (Instance instance : instances) {
|
||||||
if (instance.isHealthy()) {
|
|
||||||
result.add(new NacosServer(instance));
|
result.add(new NacosServer(instance));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user