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