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

[issue #982 & issue #978]enhance nacos config - code review

This commit is contained in:
zkzlx 2020-01-07 12:52:08 +08:00
parent 85ddda03ff
commit c348421970
6 changed files with 19 additions and 12 deletions

View File

@ -63,14 +63,9 @@ public class NacosConfigAutoConfiguration {
@Bean
public NacosContextRefresher nacosContextRefresher(
NacosConfigManager nacosConfigManager,
NacosRefreshProperties nacosRefreshProperties,
NacosRefreshHistory nacosRefreshHistory) {
// Compatible with older configurations
if (nacosConfigManager.getNacosConfigProperties().isRefreshEnabled()
&& null != nacosRefreshProperties
&& !nacosRefreshProperties.isEnabled()) {
nacosConfigManager.getNacosConfigProperties().setRefreshEnabled(false);
}
// Consider that it is not necessary to be compatible with the previous configuration
// and use the new configuration if necessary.
return new NacosContextRefresher(nacosConfigManager, nacosRefreshHistory);
}

View File

@ -51,9 +51,11 @@ public class NacosConfigManager {
if (Objects.isNull(service)) {
synchronized (NacosConfigManager.class) {
try {
if (Objects.isNull(service)) {
service = NacosFactory.createConfigService(
nacosConfigProperties.assembleConfigServiceProperties());
}
}
catch (NacosException e) {
log.error(e.getMessage());
throw new NacosConnectionFailureException(

View File

@ -76,7 +76,8 @@ public final class NacosPropertySourceRepository {
}
public static String getMapKey(String dataId, String group) {
return String.format("%s$%s", String.valueOf(dataId), String.valueOf(group));
return String.join(NacosConfigProperties.COMMAS, String.valueOf(dataId),
String.valueOf(group));
}
}

View File

@ -19,6 +19,8 @@ package com.alibaba.cloud.nacos.client;
import java.util.Date;
import java.util.Map;
import com.alibaba.cloud.nacos.NacosConfigProperties;
import org.springframework.core.env.MapPropertySource;
/**
@ -49,7 +51,7 @@ public class NacosPropertySource extends MapPropertySource {
NacosPropertySource(String group, String dataId, Map<String, Object> source,
Date timestamp, boolean isRefreshable) {
super(String.format("%s#%s", dataId, group), source);
super(String.join(NacosConfigProperties.COMMAS, dataId, group), source);
this.group = group;
this.dataId = dataId;
this.timestamp = timestamp;

View File

@ -26,10 +26,15 @@ import java.util.Date;
import java.util.LinkedList;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
public class NacosRefreshHistory {
private final static Logger log = LoggerFactory.getLogger(NacosRefreshHistory.class);
private static final int MAX_SIZE = 20;
private final LinkedList<Record> records = new LinkedList<>();
@ -43,7 +48,8 @@ public class NacosRefreshHistory {
try {
md = MessageDigest.getInstance("MD5");
}
catch (NoSuchAlgorithmException ignored) {
catch (NoSuchAlgorithmException e) {
log.error("failed to initialize MessageDigest : ", e);
}
}

View File

@ -3,6 +3,7 @@
{
"name": "spring.cloud.nacos.server-addr",
"type": "java.lang.String",
"defaultValue": "localhost:8848",
"description": "nacos server address."
},
{