update pom.xml, and format code

pull/1534/head
flystar32 6 years ago
parent 024a0cca7c
commit 4ae2983c7a

@ -21,12 +21,12 @@
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
<artifactId>spring-cloud-context</artifactId>
</dependency>
<dependency>
@ -57,12 +57,7 @@
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>

@ -34,7 +34,8 @@ import com.alibaba.nacos.api.naming.pojo.ListView;
*/
public class NacosDiscoveryClient implements DiscoveryClient {
private static final Logger LOGGER = LoggerFactory.getLogger(NacosDiscoveryClient.class);
private static final Logger LOGGER = LoggerFactory
.getLogger(NacosDiscoveryClient.class);
public static final String DESCRIPTION = "Spring Cloud Nacos Discovery Client";
@Autowired
@ -49,7 +50,7 @@ public class NacosDiscoveryClient implements DiscoveryClient {
public List<ServiceInstance> getInstances(String serviceId) {
try {
NamingService namingService = nacosRegistration.getNacosNamingService();
List<Instance> instances = namingService.selectInstances(serviceId,true);
List<Instance> instances = namingService.selectInstances(serviceId, true);
return hostToServiceInstanceList(instances, serviceId);
}
catch (Exception e) {
@ -58,25 +59,26 @@ public class NacosDiscoveryClient implements DiscoveryClient {
}
}
private static ServiceInstance hostToServiceInstance(Instance instance, String serviceId) {
private static ServiceInstance hostToServiceInstance(Instance instance,
String serviceId) {
NacosServiceInstance nacosServiceInstance = new NacosServiceInstance();
nacosServiceInstance.setHost(instance.getIp());
nacosServiceInstance.setPort(instance.getPort());
nacosServiceInstance.setServiceId(serviceId);
Map<String, String> metadata = new HashMap<String, String>();
metadata.put("instanceId", instance.getInstanceId());
metadata.put("weight", instance.getWeight()+"");
metadata.put("healthy", instance.isHealthy()+"");
metadata.put("cluster", instance.getCluster()+"");
metadata.put("weight", instance.getWeight() + "");
metadata.put("healthy", instance.isHealthy() + "");
metadata.put("cluster", instance.getCluster() + "");
metadata.putAll(instance.getMetadata());
nacosServiceInstance.setMetadata(metadata);
return nacosServiceInstance;
}
private static List<ServiceInstance> hostToServiceInstanceList(List<Instance> instances,
String serviceId) {
private static List<ServiceInstance> hostToServiceInstanceList(
List<Instance> instances, String serviceId) {
List<ServiceInstance> result = new ArrayList<ServiceInstance>(instances.size());
for (Instance instance: instances) {
for (Instance instance : instances) {
result.add(hostToServiceInstance(instance, serviceId));
}
return result;
@ -87,9 +89,11 @@ public class NacosDiscoveryClient implements DiscoveryClient {
try {
NamingService namingService = nacosRegistration.getNacosNamingService();
ListView<String> services = namingService.getServicesOfServer(1, Integer.MAX_VALUE);
ListView<String> services = namingService.getServicesOfServer(1,
Integer.MAX_VALUE);
return services.getData();
}catch( Exception e){
}
catch (Exception e) {
LOGGER.error("get service name from nacos server fail,", e);
return Collections.emptyList();
}

@ -16,7 +16,6 @@
package org.springframework.cloud.alibaba.nacos;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ -123,7 +122,6 @@ public class NacosDiscoveryProperties {
private String secretKey;
@Autowired
@JsonIgnore
private InetUtils inetUtils;
@PostConstruct
@ -190,10 +188,6 @@ public class NacosDiscoveryProperties {
this.logName = logName;
}
public InetUtils getInetUtils() {
return inetUtils;
}
public void setInetUtils(InetUtils inetUtils) {
this.inetUtils = inetUtils;
}

@ -16,7 +16,6 @@
package org.springframework.cloud.alibaba.nacos.registry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -29,16 +28,18 @@ import org.springframework.util.StringUtils;
/**
* @author xiaojing
*/
public class NacosAutoServiceRegistration extends AbstractAutoServiceRegistration<NacosRegistration> {
private static final Logger LOGGER = LoggerFactory.getLogger(NacosAutoServiceRegistration.class);
public class NacosAutoServiceRegistration
extends AbstractAutoServiceRegistration<NacosRegistration> {
private static final Logger LOGGER = LoggerFactory
.getLogger(NacosAutoServiceRegistration.class);
@Autowired
private NacosRegistration registration;
public NacosAutoServiceRegistration(ServiceRegistry<NacosRegistration> serviceRegistry,
AutoServiceRegistrationProperties autoServiceRegistrationProperties,
NacosRegistration registration) {
public NacosAutoServiceRegistration(
ServiceRegistry<NacosRegistration> serviceRegistry,
AutoServiceRegistrationProperties autoServiceRegistrationProperties,
NacosRegistration registration) {
super(serviceRegistry, autoServiceRegistrationProperties);
this.registration = registration;
}
@ -83,7 +84,6 @@ public class NacosAutoServiceRegistration extends AbstractAutoServiceRegistratio
}
@Override
protected Object getConfiguration() {
return this.registration.getNacosDiscoveryProperties();
@ -102,4 +102,3 @@ public class NacosAutoServiceRegistration extends AbstractAutoServiceRegistratio
}
}

@ -34,6 +34,7 @@ import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.client.naming.utils.UtilAndComs;
import static com.alibaba.nacos.api.PropertyKeyConst.*;
/**
* @author xiaojing
*/
@ -54,11 +55,12 @@ public class NacosRegistration implements Registration, ServiceInstance {
Properties properties = new Properties();
properties.put(SERVER_ADDR, nacosDiscoveryProperties.getServerAddr());
properties.put(NAMESPACE, nacosDiscoveryProperties.getNamespace());
properties.put(UtilAndComs.NACOS_NAMING_LOG_NAME, nacosDiscoveryProperties.getLogName());
properties.put(UtilAndComs.NACOS_NAMING_LOG_NAME,
nacosDiscoveryProperties.getLogName());
properties.put(ENDPOINT, nacosDiscoveryProperties.getEndpoint());
properties.put(ACCESS_KEY,nacosDiscoveryProperties.getAccessKey());
properties.put(SECRET_KEY,nacosDiscoveryProperties.getSecretKey());
properties.put(CLUSTER_NAME,nacosDiscoveryProperties.getClusterName());
properties.put(ACCESS_KEY, nacosDiscoveryProperties.getAccessKey());
properties.put(SECRET_KEY, nacosDiscoveryProperties.getSecretKey());
properties.put(CLUSTER_NAME, nacosDiscoveryProperties.getClusterName());
try {
nacosNamingService = NacosFactory.createNamingService(properties);
}
@ -128,15 +130,14 @@ public class NacosRegistration implements Registration, ServiceInstance {
}
public void setNacosDiscoveryProperties(
NacosDiscoveryProperties nacosDiscoveryProperties) {
NacosDiscoveryProperties nacosDiscoveryProperties) {
this.nacosDiscoveryProperties = nacosDiscoveryProperties;
}
@Override
public String toString() {
return "NacosRegistration{" +
"nacosDiscoveryProperties=" + nacosDiscoveryProperties +
", nacosNamingService=" + nacosNamingService +
'}';
return "NacosRegistration{" + "nacosDiscoveryProperties="
+ nacosDiscoveryProperties + ", nacosNamingService=" + nacosNamingService
+ '}';
}
}

@ -31,7 +31,7 @@ public class NacosServer extends Server {
private final Instance instance;
private final Map<String, String> metadata;
public NacosServer(Instance instance) {
public NacosServer(final Instance instance) {
super(instance.getIp(), instance.getPort());
this.instance = instance;
this.metaInfo = new MetaInfo() {

Loading…
Cancel
Save