mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
merge endpoint and endpoint configuration
This commit is contained in:
parent
ab0801f10f
commit
3fdacebdcf
@ -21,12 +21,8 @@ import com.alibaba.nacos.api.config.ConfigService;
|
|||||||
|
|
||||||
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.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.core.env.Environment;
|
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
@ -91,12 +87,6 @@ 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.
|
||||||
*/
|
*/
|
||||||
@ -272,14 +262,6 @@ 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
|
||||||
@ -325,12 +307,11 @@ 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 + '\''
|
||||||
+ ", endpointPort='" + endpointPort + '\'' + ", namespace='" + namespace
|
+ ", namespace='" + namespace + '\'' + ", accessKey='" + accessKey + '\''
|
||||||
+ '\'' + ", accessKey='" + accessKey + '\'' + ", secretKey='" + secretKey
|
+ ", secretKey='" + secretKey + '\'' + ", contextPath='" + contextPath
|
||||||
+ '\'' + ", contextPath='" + contextPath + '\'' + ", clusterName='"
|
+ '\'' + ", clusterName='" + clusterName + '\'' + ", name='" + name + '\''
|
||||||
+ clusterName + '\'' + ", name='" + name + '\'' + ", sharedDataids='"
|
+ ", sharedDataids='" + sharedDataids + '\'' + ", refreshableDataids='"
|
||||||
+ sharedDataids + '\'' + ", refreshableDataids='" + refreshableDataids
|
+ refreshableDataids + '\'' + ", extConfig=" + extConfig + '}';
|
||||||
+ '\'' + ", extConfig=" + extConfig + '}';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigService configServiceInstance() {
|
public ConfigService configServiceInstance() {
|
||||||
@ -347,8 +328,17 @@ public class NacosConfigProperties {
|
|||||||
properties.put(SECRET_KEY, Objects.toString(this.secretKey, ""));
|
properties.put(SECRET_KEY, Objects.toString(this.secretKey, ""));
|
||||||
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_PORT, Objects.toString(this.endpointPort, ""));
|
String endpoint = Objects.toString(this.endpoint, "");
|
||||||
|
if (endpoint.contains(":")) {
|
||||||
|
int index = endpoint.indexOf(":");
|
||||||
|
properties.put(ENDPOINT, endpoint.substring(0, index));
|
||||||
|
properties.put(ENDPOINT_PORT, endpoint.substring(index + 1));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
properties.put(ENDPOINT, endpoint);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
configService = NacosFactory.createConfigService(properties);
|
configService = NacosFactory.createConfigService(properties);
|
||||||
return configService;
|
return configService;
|
||||||
|
@ -60,7 +60,6 @@ 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",
|
||||||
@ -154,7 +153,6 @@ public class NacosConfigurationTests {
|
|||||||
|
|
||||||
checkoutNacosConfigServerAddr();
|
checkoutNacosConfigServerAddr();
|
||||||
checkoutNacosConfigEndpoint();
|
checkoutNacosConfigEndpoint();
|
||||||
checkoutNacosConfigEndpointPort();
|
|
||||||
checkoutNacosConfigNamespace();
|
checkoutNacosConfigNamespace();
|
||||||
checkoutNacosConfigClusterName();
|
checkoutNacosConfigClusterName();
|
||||||
checkoutNacosConfigAccessKey();
|
checkoutNacosConfigAccessKey();
|
||||||
@ -183,12 +181,6 @@ 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,12 +59,6 @@ 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.
|
||||||
*/
|
*/
|
||||||
@ -341,26 +335,18 @@ 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 + '\'' + ", endpointPort='" + endpointPort
|
+ ", endpoint='" + endpoint + '\'' + ", namespace='" + namespace + '\''
|
||||||
+ '\'' + ", namespace='" + namespace + '\'' + ", watchDelay=" + watchDelay
|
+ ", watchDelay=" + watchDelay + ", logName='" + logName + '\''
|
||||||
+ ", logName='" + logName + '\'' + ", service='" + service + '\''
|
+ ", service='" + service + '\'' + ", weight=" + weight
|
||||||
+ ", weight=" + weight + ", clusterName='" + clusterName + '\''
|
+ ", clusterName='" + clusterName + '\'' + ", namingLoadCacheAtStart='"
|
||||||
+ ", namingLoadCacheAtStart='" + namingLoadCacheAtStart + '\''
|
+ namingLoadCacheAtStart + '\'' + ", metadata=" + metadata
|
||||||
+ ", metadata=" + metadata + ", registerEnabled=" + registerEnabled
|
+ ", registerEnabled=" + registerEnabled + ", ip='" + ip + '\''
|
||||||
+ ", ip='" + ip + '\'' + ", networkInterface='" + networkInterface + '\''
|
+ ", networkInterface='" + networkInterface + '\'' + ", port=" + port
|
||||||
+ ", port=" + port + ", secure=" + secure + ", accessKey='" + accessKey
|
+ ", secure=" + secure + ", accessKey='" + accessKey + '\''
|
||||||
+ '\'' + ", secretKey='" + secretKey + '\'' + '}';
|
+ ", secretKey='" + secretKey + '\'' + '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
public void overrideFromEnv(Environment env) {
|
public void overrideFromEnv(Environment env) {
|
||||||
@ -393,10 +379,6 @@ 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() {
|
||||||
@ -409,8 +391,16 @@ public class NacosDiscoveryProperties {
|
|||||||
properties.put(SERVER_ADDR, serverAddr);
|
properties.put(SERVER_ADDR, serverAddr);
|
||||||
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_PORT, endpointPort);
|
if (endpoint.contains(":")) {
|
||||||
|
int index = endpoint.indexOf(":");
|
||||||
|
properties.put(ENDPOINT, endpoint.substring(0, index));
|
||||||
|
properties.put(ENDPOINT_PORT, endpoint.substring(index + 1));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
properties.put(ENDPOINT, endpoint);
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
@ -48,7 +48,6 @@ 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",
|
||||||
@ -84,7 +83,6 @@ public class NacosAutoServiceRegistrationTests {
|
|||||||
|
|
||||||
checkoutNacosDiscoveryServerAddr();
|
checkoutNacosDiscoveryServerAddr();
|
||||||
checkoutNacosDiscoveryEndpoint();
|
checkoutNacosDiscoveryEndpoint();
|
||||||
checkoutNacosDiscoveryEndpointPort();
|
|
||||||
checkoutNacosDiscoveryNamespace();
|
checkoutNacosDiscoveryNamespace();
|
||||||
checkoutNacosDiscoveryLogName();
|
checkoutNacosDiscoveryLogName();
|
||||||
checkoutNacosDiscoveryWeight();
|
checkoutNacosDiscoveryWeight();
|
||||||
@ -121,12 +119,6 @@ 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