mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Merge pull request #53 from flystar32/master
update nacos version to 0.3.0-RC1
This commit is contained in:
commit
a21343d589
@ -18,7 +18,7 @@
|
||||
<properties>
|
||||
<sentinel.version>0.2.0</sentinel.version>
|
||||
<oss.version>3.1.0</oss.version>
|
||||
<nacos.version>0.2.1</nacos.version>
|
||||
<nacos.version>0.3.0-RC1</nacos.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
|
@ -19,15 +19,11 @@ package org.springframework.cloud.alibaba.nacos;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.client.DefaultServiceInstance;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import com.alibaba.nacos.api.naming.NamingService;
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import com.alibaba.nacos.api.naming.pojo.ListView;
|
||||
@ -44,17 +40,6 @@ public class NacosDiscoveryClient implements DiscoveryClient {
|
||||
@Autowired
|
||||
private NacosDiscoveryProperties discoveryProperties;
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
private NamingService namingService;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
discoveryProperties.overrideFromEnv(environment);
|
||||
namingService = discoveryProperties.getNamingService();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return DESCRIPTION;
|
||||
@ -63,7 +48,8 @@ public class NacosDiscoveryClient implements DiscoveryClient {
|
||||
@Override
|
||||
public List<ServiceInstance> getInstances(String serviceId) {
|
||||
try {
|
||||
List<Instance> instances = namingService.getAllInstances(serviceId);
|
||||
List<Instance> instances = discoveryProperties.namingServiceInstance()
|
||||
.getAllInstances(serviceId);
|
||||
return hostToServiceInstanceList(instances, serviceId);
|
||||
}
|
||||
catch (Exception e) {
|
||||
@ -103,8 +89,8 @@ public class NacosDiscoveryClient implements DiscoveryClient {
|
||||
public List<String> getServices() {
|
||||
|
||||
try {
|
||||
ListView<String> services = namingService.getServicesOfServer(1,
|
||||
Integer.MAX_VALUE);
|
||||
ListView<String> services = discoveryProperties.namingServiceInstance()
|
||||
.getServicesOfServer(1, Integer.MAX_VALUE);
|
||||
return services.getData();
|
||||
}
|
||||
catch (Exception e) {
|
||||
@ -114,6 +100,6 @@ public class NacosDiscoveryClient implements DiscoveryClient {
|
||||
}
|
||||
|
||||
public NamingService getNamingService() {
|
||||
return namingService;
|
||||
return discoveryProperties.namingServiceInstance();
|
||||
}
|
||||
}
|
||||
|
@ -142,6 +142,11 @@ public class NacosDiscoveryProperties {
|
||||
@Autowired
|
||||
private InetUtils inetUtils;
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
private NamingService namingService;
|
||||
|
||||
@PostConstruct
|
||||
public void init() throws SocketException {
|
||||
|
||||
@ -180,6 +185,8 @@ public class NacosDiscoveryProperties {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
this.overrideFromEnv(environment);
|
||||
}
|
||||
|
||||
public String getEndpoint() {
|
||||
@ -350,7 +357,12 @@ public class NacosDiscoveryProperties {
|
||||
}
|
||||
}
|
||||
|
||||
public NamingService getNamingService() {
|
||||
public NamingService namingServiceInstance() {
|
||||
|
||||
if (null != namingService) {
|
||||
return namingService;
|
||||
}
|
||||
|
||||
Properties properties = new Properties();
|
||||
properties.put(SERVER_ADDR, serverAddr);
|
||||
properties.put(NAMESPACE, namespace);
|
||||
@ -360,7 +372,8 @@ public class NacosDiscoveryProperties {
|
||||
properties.put(SECRET_KEY, secretKey);
|
||||
properties.put(CLUSTER_NAME, clusterName);
|
||||
try {
|
||||
return NacosFactory.createNamingService(properties);
|
||||
namingService = NacosFactory.createNamingService(properties);
|
||||
return namingService;
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOGGER.error("create naming service error!properties={},e=,", this, e);
|
||||
|
@ -29,7 +29,6 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
|
||||
import org.springframework.cloud.alibaba.nacos.NacosDiscoveryClient;
|
||||
import org.springframework.cloud.alibaba.nacos.NacosDiscoveryProperties;
|
||||
|
||||
/**
|
||||
@ -45,9 +44,6 @@ public class NacosDiscoveryEndpoint {
|
||||
@Autowired
|
||||
private NacosDiscoveryProperties nacosDiscoveryProperties;
|
||||
|
||||
@Autowired
|
||||
private NacosDiscoveryClient discoveryClient;
|
||||
|
||||
/**
|
||||
* @return nacos discovery endpoint
|
||||
*/
|
||||
@ -56,7 +52,7 @@ public class NacosDiscoveryEndpoint {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("NacosDiscoveryProperties", nacosDiscoveryProperties);
|
||||
|
||||
NamingService namingService = discoveryClient.getNamingService();
|
||||
NamingService namingService = nacosDiscoveryProperties.namingServiceInstance();
|
||||
List<ServiceInfo> subscribe = Collections.emptyList();
|
||||
|
||||
try {
|
||||
|
@ -48,15 +48,10 @@ public class NacosRegistration implements Registration, ServiceInstance {
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
private NamingService nacosNamingService;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
|
||||
Environment env = context.getEnvironment();
|
||||
nacosDiscoveryProperties.overrideFromEnv(context.getEnvironment());
|
||||
nacosNamingService = nacosDiscoveryProperties.getNamingService();
|
||||
|
||||
Integer managementPort = ManagementServerPortUtils.getPort(context);
|
||||
if (null != managementPort) {
|
||||
Map<String, String> metadata = nacosDiscoveryProperties.getMetadata();
|
||||
@ -124,11 +119,7 @@ public class NacosRegistration implements Registration, ServiceInstance {
|
||||
}
|
||||
|
||||
public NamingService getNacosNamingService() {
|
||||
return nacosNamingService;
|
||||
}
|
||||
|
||||
public void setNacosNamingService(NamingService nacosNamingService) {
|
||||
this.nacosNamingService = nacosNamingService;
|
||||
return nacosDiscoveryProperties.namingServiceInstance();
|
||||
}
|
||||
|
||||
public void setNacosDiscoveryProperties(
|
||||
@ -139,7 +130,6 @@ public class NacosRegistration implements Registration, ServiceInstance {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NacosRegistration{" + "nacosDiscoveryProperties="
|
||||
+ nacosDiscoveryProperties + ", nacosNamingService=" + nacosNamingService
|
||||
+ '}';
|
||||
+ nacosDiscoveryProperties + '}';
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user