mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
parent
97a77d5c2b
commit
c932e03e36
@ -36,6 +36,7 @@ import static com.alibaba.nacos.api.PropertyKeyConst.CLUSTER_NAME;
|
|||||||
import static com.alibaba.nacos.api.PropertyKeyConst.CONTEXT_PATH;
|
import static com.alibaba.nacos.api.PropertyKeyConst.CONTEXT_PATH;
|
||||||
import static com.alibaba.nacos.api.PropertyKeyConst.ENCODE;
|
import static com.alibaba.nacos.api.PropertyKeyConst.ENCODE;
|
||||||
import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT;
|
import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT;
|
||||||
|
import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT_PORT;
|
||||||
import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE;
|
import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE;
|
||||||
import static com.alibaba.nacos.api.PropertyKeyConst.SECRET_KEY;
|
import static com.alibaba.nacos.api.PropertyKeyConst.SECRET_KEY;
|
||||||
import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR;
|
import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR;
|
||||||
@ -90,6 +91,12 @@ public class NacosConfigProperties {
|
|||||||
*/
|
*/
|
||||||
private String endpoint;
|
private String endpoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* endpoint port for Nacos, the domain port of a service, through which the server
|
||||||
|
* address can be dynamically obtained.
|
||||||
|
*/
|
||||||
|
private String endpointPort;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* namespace, separation configuration of different environments.
|
* namespace, separation configuration of different environments.
|
||||||
*/
|
*/
|
||||||
@ -265,6 +272,14 @@ public class NacosConfigProperties {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getEndpointPort() {
|
||||||
|
return endpointPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEndpointPort(String endpointPort) {
|
||||||
|
this.endpointPort = endpointPort;
|
||||||
|
}
|
||||||
|
|
||||||
public static class Config {
|
public static class Config {
|
||||||
/**
|
/**
|
||||||
* the data id of extended configuration
|
* the data id of extended configuration
|
||||||
@ -310,11 +325,12 @@ public class NacosConfigProperties {
|
|||||||
+ ", encode='" + encode + '\'' + ", group='" + group + '\'' + ", prefix='"
|
+ ", encode='" + encode + '\'' + ", group='" + group + '\'' + ", prefix='"
|
||||||
+ prefix + '\'' + ", fileExtension='" + fileExtension + '\''
|
+ prefix + '\'' + ", fileExtension='" + fileExtension + '\''
|
||||||
+ ", timeout=" + timeout + ", endpoint='" + endpoint + '\''
|
+ ", timeout=" + timeout + ", endpoint='" + endpoint + '\''
|
||||||
+ ", namespace='" + namespace + '\'' + ", accessKey='" + accessKey + '\''
|
+ ", endpointPort='" + endpointPort + '\'' + ", namespace='" + namespace
|
||||||
+ ", secretKey='" + secretKey + '\'' + ", contextPath='" + contextPath
|
+ '\'' + ", accessKey='" + accessKey + '\'' + ", secretKey='" + secretKey
|
||||||
+ '\'' + ", clusterName='" + clusterName + '\'' + ", name='" + name + '\''
|
+ '\'' + ", contextPath='" + contextPath + '\'' + ", clusterName='"
|
||||||
+ ", sharedDataids='" + sharedDataids + '\'' + ", refreshableDataids='"
|
+ clusterName + '\'' + ", name='" + name + '\'' + ", sharedDataids='"
|
||||||
+ refreshableDataids + '\'' + ", extConfig=" + extConfig + '}';
|
+ sharedDataids + '\'' + ", refreshableDataids='" + refreshableDataids
|
||||||
|
+ '\'' + ", extConfig=" + extConfig + '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigService configServiceInstance() {
|
public ConfigService configServiceInstance() {
|
||||||
@ -332,6 +348,7 @@ public class NacosConfigProperties {
|
|||||||
properties.put(CONTEXT_PATH, Objects.toString(this.contextPath, ""));
|
properties.put(CONTEXT_PATH, Objects.toString(this.contextPath, ""));
|
||||||
properties.put(CLUSTER_NAME, Objects.toString(this.clusterName, ""));
|
properties.put(CLUSTER_NAME, Objects.toString(this.clusterName, ""));
|
||||||
properties.put(ENDPOINT, Objects.toString(this.endpoint, ""));
|
properties.put(ENDPOINT, Objects.toString(this.endpoint, ""));
|
||||||
|
properties.put(ENDPOINT_PORT, Objects.toString(this.endpointPort, ""));
|
||||||
try {
|
try {
|
||||||
configService = NacosFactory.createConfigService(properties);
|
configService = NacosFactory.createConfigService(properties);
|
||||||
return configService;
|
return configService;
|
||||||
|
@ -60,6 +60,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||||||
"spring.application.name=myTestService1", "spring.profiles.active=dev,test",
|
"spring.application.name=myTestService1", "spring.profiles.active=dev,test",
|
||||||
"spring.cloud.nacos.config.server-addr=127.0.0.1:8848",
|
"spring.cloud.nacos.config.server-addr=127.0.0.1:8848",
|
||||||
"spring.cloud.nacos.config.endpoint=test-endpoint",
|
"spring.cloud.nacos.config.endpoint=test-endpoint",
|
||||||
|
"spring.cloud.nacos.config.endpoint-port=8081",
|
||||||
"spring.cloud.nacos.config.namespace=test-namespace",
|
"spring.cloud.nacos.config.namespace=test-namespace",
|
||||||
"spring.cloud.nacos.config.encode=utf-8",
|
"spring.cloud.nacos.config.encode=utf-8",
|
||||||
"spring.cloud.nacos.config.timeout=1000",
|
"spring.cloud.nacos.config.timeout=1000",
|
||||||
@ -153,6 +154,7 @@ public class NacosConfigurationTests {
|
|||||||
|
|
||||||
checkoutNacosConfigServerAddr();
|
checkoutNacosConfigServerAddr();
|
||||||
checkoutNacosConfigEndpoint();
|
checkoutNacosConfigEndpoint();
|
||||||
|
checkoutNacosConfigEndpointPort();
|
||||||
checkoutNacosConfigNamespace();
|
checkoutNacosConfigNamespace();
|
||||||
checkoutNacosConfigClusterName();
|
checkoutNacosConfigClusterName();
|
||||||
checkoutNacosConfigAccessKey();
|
checkoutNacosConfigAccessKey();
|
||||||
@ -181,6 +183,12 @@ public class NacosConfigurationTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkoutNacosConfigEndpointPort() {
|
||||||
|
assertEquals("NacosConfigProperties endpoint port is wrong", "8081",
|
||||||
|
properties.getEndpointPort());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void checkoutNacosConfigNamespace() {
|
private void checkoutNacosConfigNamespace() {
|
||||||
assertEquals("NacosConfigProperties namespace is wrong", "test-namespace",
|
assertEquals("NacosConfigProperties namespace is wrong", "test-namespace",
|
||||||
properties.getNamespace());
|
properties.getNamespace());
|
||||||
|
@ -59,6 +59,12 @@ public class NacosDiscoveryProperties {
|
|||||||
*/
|
*/
|
||||||
private String endpoint;
|
private String endpoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the domain port of a service, through which the server address can be dynamically
|
||||||
|
* obtained.
|
||||||
|
*/
|
||||||
|
private String endpointPort;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* namespace, separation registry of different environments.
|
* namespace, separation registry of different environments.
|
||||||
*/
|
*/
|
||||||
@ -335,18 +341,26 @@ public class NacosDiscoveryProperties {
|
|||||||
this.watchDelay = watchDelay;
|
this.watchDelay = watchDelay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getEndpointPort() {
|
||||||
|
return endpointPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEndpointPort(String endpointPort) {
|
||||||
|
this.endpointPort = endpointPort;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "NacosDiscoveryProperties{" + "serverAddr='" + serverAddr + '\''
|
return "NacosDiscoveryProperties{" + "serverAddr='" + serverAddr + '\''
|
||||||
+ ", endpoint='" + endpoint + '\'' + ", namespace='" + namespace + '\''
|
+ ", endpoint='" + endpoint + '\'' + ", endpointPort='" + endpointPort
|
||||||
+ ", watchDelay=" + watchDelay + ", logName='" + logName + '\''
|
+ '\'' + ", namespace='" + namespace + '\'' + ", watchDelay=" + watchDelay
|
||||||
+ ", service='" + service + '\'' + ", weight=" + weight
|
+ ", logName='" + logName + '\'' + ", service='" + service + '\''
|
||||||
+ ", clusterName='" + clusterName + '\'' + ", namingLoadCacheAtStart='"
|
+ ", weight=" + weight + ", clusterName='" + clusterName + '\''
|
||||||
+ namingLoadCacheAtStart + '\'' + ", metadata=" + metadata
|
+ ", namingLoadCacheAtStart='" + namingLoadCacheAtStart + '\''
|
||||||
+ ", registerEnabled=" + registerEnabled + ", ip='" + ip + '\''
|
+ ", metadata=" + metadata + ", registerEnabled=" + registerEnabled
|
||||||
+ ", networkInterface='" + networkInterface + '\'' + ", port=" + port
|
+ ", ip='" + ip + '\'' + ", networkInterface='" + networkInterface + '\''
|
||||||
+ ", secure=" + secure + ", accessKey='" + accessKey + '\''
|
+ ", port=" + port + ", secure=" + secure + ", accessKey='" + accessKey
|
||||||
+ ", secretKey='" + secretKey + '\'' + '}';
|
+ '\'' + ", secretKey='" + secretKey + '\'' + '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
public void overrideFromEnv(Environment env) {
|
public void overrideFromEnv(Environment env) {
|
||||||
@ -379,6 +393,10 @@ public class NacosDiscoveryProperties {
|
|||||||
this.setEndpoint(
|
this.setEndpoint(
|
||||||
env.resolvePlaceholders("${spring.cloud.nacos.discovery.endpoint:}"));
|
env.resolvePlaceholders("${spring.cloud.nacos.discovery.endpoint:}"));
|
||||||
}
|
}
|
||||||
|
if (StringUtils.isEmpty(this.getEndpointPort())) {
|
||||||
|
this.setEndpointPort(env.resolvePlaceholders(
|
||||||
|
"${spring.cloud.nacos.discovery.endpoint-port:}"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public NamingService namingServiceInstance() {
|
public NamingService namingServiceInstance() {
|
||||||
@ -392,6 +410,7 @@ public class NacosDiscoveryProperties {
|
|||||||
properties.put(NAMESPACE, namespace);
|
properties.put(NAMESPACE, namespace);
|
||||||
properties.put(UtilAndComs.NACOS_NAMING_LOG_NAME, logName);
|
properties.put(UtilAndComs.NACOS_NAMING_LOG_NAME, logName);
|
||||||
properties.put(ENDPOINT, endpoint);
|
properties.put(ENDPOINT, endpoint);
|
||||||
|
properties.put(ENDPOINT_PORT, endpointPort);
|
||||||
properties.put(ACCESS_KEY, accessKey);
|
properties.put(ACCESS_KEY, accessKey);
|
||||||
properties.put(SECRET_KEY, secretKey);
|
properties.put(SECRET_KEY, secretKey);
|
||||||
properties.put(CLUSTER_NAME, clusterName);
|
properties.put(CLUSTER_NAME, clusterName);
|
||||||
|
@ -18,6 +18,8 @@ package org.springframework.cloud.alibaba.nacos.discovery;
|
|||||||
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.cloud.alibaba.nacos.ConditionalOnNacosDiscoveryEnabled;
|
import org.springframework.cloud.alibaba.nacos.ConditionalOnNacosDiscoveryEnabled;
|
||||||
import org.springframework.cloud.alibaba.nacos.NacosDiscoveryProperties;
|
import org.springframework.cloud.alibaba.nacos.NacosDiscoveryProperties;
|
||||||
@ -45,6 +47,7 @@ public class NacosDiscoveryClientAutoConfiguration {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
|
@ConditionalOnProperty(value = "spring.cloud.nacos.discovery.watch.enabled", matchIfMissing = true)
|
||||||
public NacosWatch nacosWatch(NacosDiscoveryProperties nacosDiscoveryProperties) {
|
public NacosWatch nacosWatch(NacosDiscoveryProperties nacosDiscoveryProperties) {
|
||||||
return new NacosWatch(nacosDiscoveryProperties);
|
return new NacosWatch(nacosDiscoveryProperties);
|
||||||
}
|
}
|
||||||
|
@ -16,5 +16,11 @@
|
|||||||
"type": "java.lang.Boolean",
|
"type": "java.lang.Boolean",
|
||||||
"defaultValue": "false",
|
"defaultValue": "false",
|
||||||
"description": "naming load from local cache at application start ."
|
"description": "naming load from local cache at application start ."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "spring.cloud.nacos.discovery.watch.enabled",
|
||||||
|
"type": "java.lang.Boolean",
|
||||||
|
"defaultValue": "true",
|
||||||
|
"description": "enable nacos discovery watch or not ."
|
||||||
}
|
}
|
||||||
]}
|
]}
|
||||||
|
@ -48,6 +48,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
|||||||
"spring.application.name=myTestService1",
|
"spring.application.name=myTestService1",
|
||||||
"spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848",
|
"spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848",
|
||||||
"spring.cloud.nacos.discovery.endpoint=test-endpoint",
|
"spring.cloud.nacos.discovery.endpoint=test-endpoint",
|
||||||
|
"spring.cloud.nacos.discovery.endpoint-port=8081",
|
||||||
"spring.cloud.nacos.discovery.namespace=test-namespace",
|
"spring.cloud.nacos.discovery.namespace=test-namespace",
|
||||||
"spring.cloud.nacos.discovery.log-name=test-logName",
|
"spring.cloud.nacos.discovery.log-name=test-logName",
|
||||||
"spring.cloud.nacos.discovery.weight=2",
|
"spring.cloud.nacos.discovery.weight=2",
|
||||||
@ -83,6 +84,7 @@ public class NacosAutoServiceRegistrationTests {
|
|||||||
|
|
||||||
checkoutNacosDiscoveryServerAddr();
|
checkoutNacosDiscoveryServerAddr();
|
||||||
checkoutNacosDiscoveryEndpoint();
|
checkoutNacosDiscoveryEndpoint();
|
||||||
|
checkoutNacosDiscoveryEndpointPort();
|
||||||
checkoutNacosDiscoveryNamespace();
|
checkoutNacosDiscoveryNamespace();
|
||||||
checkoutNacosDiscoveryLogName();
|
checkoutNacosDiscoveryLogName();
|
||||||
checkoutNacosDiscoveryWeight();
|
checkoutNacosDiscoveryWeight();
|
||||||
@ -119,6 +121,12 @@ public class NacosAutoServiceRegistrationTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkoutNacosDiscoveryEndpointPort() {
|
||||||
|
assertEquals("NacosDiscoveryProperties endpoint port was wrong", "8081",
|
||||||
|
properties.getEndpointPort());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void checkoutNacosDiscoveryNamespace() {
|
private void checkoutNacosDiscoveryNamespace() {
|
||||||
assertEquals("NacosDiscoveryProperties namespace was wrong", "test-namespace",
|
assertEquals("NacosDiscoveryProperties namespace was wrong", "test-namespace",
|
||||||
properties.getNamespace());
|
properties.getNamespace());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user