Commit 5c5f4d30 by Nepxion

增加Nacos服务注册发现

parent 53e08605
......@@ -29,7 +29,7 @@ public class ApolloAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public Config apolloConfig() {
String namespace = environment.getProperty(ApolloConstant.APOLLO_DISCOVERY_NAMESPACE);
String namespace = environment.getProperty(ApolloConstant.APOLLO_PLUGIN_NAMESPACE);
if (StringUtils.isNotEmpty(namespace)) {
return ConfigService.getConfig(namespace);
} else {
......
......@@ -13,5 +13,5 @@ import com.ctrip.framework.apollo.core.ConfigConsts;
public class ApolloConstant implements ConfigConsts {
public static final String TYPE = "Apollo";
public static final String APOLLO_DISCOVERY_NAMESPACE = "apollo.discovery.namespace";
public static final String APOLLO_PLUGIN_NAMESPACE = "apollo.plugin.namespace";
}
\ No newline at end of file
......@@ -41,11 +41,41 @@ public class NacosAutoConfiguration {
throw new IllegalArgumentException(NacosConstant.NACOS_SERVER_ADDR + " can't be null or empty");
}
String namespace = environment.getProperty(NacosConstant.NACOS_DISCOVERY_NAMESPACE);
String accessKey = environment.getProperty(NacosConstant.NACOS_ACCESS_KEY);
if (StringUtils.isNotEmpty(accessKey)) {
properties.put(NacosConstant.ACCESS_KEY, accessKey);
}
String secretKey = environment.getProperty(NacosConstant.NACOS_SECRET_KEY);
if (StringUtils.isNotEmpty(secretKey)) {
properties.put(NacosConstant.SECRET_KEY, secretKey);
}
String namespace = environment.getProperty(NacosConstant.NACOS_PLUGIN_NAMESPACE);
if (StringUtils.isNotEmpty(namespace)) {
properties.put(NacosConstant.NAMESPACE, namespace);
}
String clusterName = environment.getProperty(NacosConstant.NACOS_PLUGIN_CLUSTER_NAME);
if (StringUtils.isNotEmpty(clusterName)) {
properties.put(NacosConstant.CLUSTER_NAME, clusterName);
}
String contextPath = environment.getProperty(NacosConstant.NACOS_PLUGIN_CONTEXT_PATH);
if (StringUtils.isNotEmpty(contextPath)) {
properties.put(NacosConstant.CONTEXT_PATH, contextPath);
}
String endpoint = environment.getProperty(NacosConstant.NACOS_PLUGIN_ENDPOINT);
if (StringUtils.isNotEmpty(endpoint)) {
properties.put(NacosConstant.ENDPOINT, endpoint);
}
String encode = environment.getProperty(NacosConstant.NACOS_PLUGIN_ENCODE);
if (StringUtils.isNotEmpty(encode)) {
properties.put(NacosConstant.ENCODE, encode);
}
return NacosFactory.createConfigService(properties);
}
......
......@@ -14,8 +14,14 @@ import com.alibaba.nacos.api.PropertyKeyConst;
public class NacosConstant extends PropertyKeyConst {
public static final String TYPE = "Nacos";
public static final String NACOS_SERVER_ADDR = "nacos.server-addr";
public static final String NACOS_DISCOVERY_NAMESPACE = "nacos.discovery.namespace";
public static final String NACOS_DISCOVERY_TIMEOUT = "nacos.discovery.timout";
public static final String NACOS_ACCESS_KEY = "nacos.access-key";
public static final String NACOS_SECRET_KEY = "nacos.secret-key";
public static final String NACOS_PLUGIN_NAMESPACE = "nacos.plugin.namespace";
public static final String NACOS_PLUGIN_CLUSTER_NAME = "nacos.plugin.cluster-name";
public static final String NACOS_PLUGIN_CONTEXT_PATH = "nacos.plugin.context-path";
public static final String NACOS_PLUGIN_ENDPOINT = "nacos.plugin.endpoint";
public static final String NACOS_PLUGIN_ENCODE = "nacos.plugin.encode";
public static final String NACOS_PLUGIN_TIMEOUT = "nacos.plugin.timout";
public static final long DEFAULT_TIMEOUT = 30000;
}
\ No newline at end of file
......@@ -27,7 +27,7 @@ public class NacosOperation {
private Environment environment;
public String getConfig(String group, String serviceId) throws NacosException {
long timeout = environment.getProperty(NacosConstant.NACOS_DISCOVERY_TIMEOUT, Long.class, NacosConstant.DEFAULT_TIMEOUT);
long timeout = environment.getProperty(NacosConstant.NACOS_PLUGIN_TIMEOUT, Long.class, NacosConstant.DEFAULT_TIMEOUT);
return nacosConfigService.getConfig(serviceId, group, timeout);
}
......
......@@ -24,8 +24,7 @@ ribbon.ConnectTimeout=60000
# Nacos config
nacos.server-addr=localhost:8080
# nacos.discovery.namespace=application
# nacos.discovery.timout=30000
# nacos.plugin.namespace=application
# Redis config
spring.redis.host=localhost
......
......@@ -25,12 +25,11 @@ ribbon.ConnectTimeout=60000
# Apollo config
app.id=discovery
apollo.meta=http://localhost:8080
# apollo.discovery.namespace=application
# apollo.plugin.namespace=application
# Nacos config
nacos.server-addr=localhost:8080
# nacos.discovery.namespace=application
# nacos.discovery.timout=30000
# nacos.plugin.namespace=application
# Redis config
spring.redis.host=localhost
......
......@@ -26,12 +26,11 @@ ribbon.ConnectTimeout=60000
# Apollo config
app.id=discovery
apollo.meta=http://localhost:8080
# apollo.discovery.namespace=application
# apollo.plugin.namespace=application
# Nacos config
nacos.server-addr=localhost:8080
# nacos.discovery.namespace=application
# nacos.discovery.timout=30000
# nacos.plugin.namespace=application
# Redis config
spring.redis.host=localhost
......
......@@ -25,12 +25,11 @@ ribbon.ConnectTimeout=60000
# Apollo config
app.id=discovery
apollo.meta=http://localhost:8080
# apollo.discovery.namespace=application
# apollo.plugin.namespace=application
# Nacos config
nacos.server-addr=localhost:8080
# nacos.discovery.namespace=application
# nacos.discovery.timout=30000
# nacos.plugin.namespace=application
# Redis config
spring.redis.host=localhost
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment