Merge pull request #1233 from yuhuangbin/nacos-enhance

Upgrade Nacos client version
pull/1247/head
Mercy Ma 5 years ago committed by GitHub
commit 506e1e6601
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -21,7 +21,7 @@
<sentinel.version>1.7.1</sentinel.version> <sentinel.version>1.7.1</sentinel.version>
<oss.version>3.1.0</oss.version> <oss.version>3.1.0</oss.version>
<seata.version>1.0.0</seata.version> <seata.version>1.0.0</seata.version>
<nacos.client.version>1.1.4</nacos.client.version> <nacos.client.version>1.2.0</nacos.client.version>
<nacos.config.version>0.8.0</nacos.config.version> <nacos.config.version>0.8.0</nacos.config.version>
<acm.version>1.0.9</acm.version> <acm.version>1.0.9</acm.version>
<ans.version>1.0.1</ans.version> <ans.version>1.0.1</ans.version>

@ -1,6 +1,10 @@
spring.application.name=nacos-config-example spring.application.name=nacos-config-example
spring.cloud.nacos.config.server-addr=127.0.0.1:8848 spring.cloud.nacos.config.server-addr=127.0.0.1:8848
#nacos certification information
spring.cloud.nacos.username=nacos
spring.cloud.nacos.password=nacos
#spring.cloud.nacos.config.refreshable-dataids=common.properties #spring.cloud.nacos.config.refreshable-dataids=common.properties
#spring.cloud.nacos.config.shared-data-ids=common.properties,base-common.properties #spring.cloud.nacos.config.shared-data-ids=common.properties,base-common.properties
spring.cloud.nacos.config.shared-configs[0]= common333.properties spring.cloud.nacos.config.shared-configs[0]= common333.properties
@ -16,5 +20,6 @@ spring.cloud.nacos.config.extension-configs[1]= extension2.properties
spring.cloud.nacos.config.extension-configs[2].data-id= extension3.json spring.cloud.nacos.config.extension-configs[2].data-id= extension3.json
#spring.cloud.nacos.config.refresh-enabled=true #spring.cloud.nacos.config.refresh-enabled=true

@ -35,7 +35,7 @@ import org.springframework.web.client.RestTemplate;
* @author xiaojing * @author xiaojing
*/ */
@SpringBootApplication @SpringBootApplication
@EnableDiscoveryClient(autoRegister = false) @EnableDiscoveryClient(autoRegister = true)
@EnableFeignClients @EnableFeignClients
public class ConsumerApplication { public class ConsumerApplication {

@ -3,6 +3,9 @@ server.port=18083
management.endpoints.web.exposure.include=* management.endpoints.web.exposure.include=*
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.username=nacos
spring.cloud.nacos.password=nacos
feign.sentinel.enabled=true feign.sentinel.enabled=true
spring.cloud.sentinel.transport.dashboard=localhost:8080 spring.cloud.sentinel.transport.dashboard=localhost:8080

@ -3,6 +3,9 @@ server.port=18083
management.endpoints.web.exposure.include=* management.endpoints.web.exposure.include=*
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.username=nacos
spring.cloud.nacos.password=nacos
spring.cloud.loadbalancer.ribbon.enabled=false spring.cloud.loadbalancer.ribbon.enabled=false
feign.sentinel.enabled=true feign.sentinel.enabled=true

@ -1,5 +1,9 @@
server.port=18082 server.port=18082
spring.application.name=service-provider spring.application.name=service-provider
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.username=nacos
spring.cloud.nacos.password=nacos
management.endpoints.web.exposure.include=* management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always management.endpoint.health.show-details=always

@ -3,6 +3,8 @@ spring:
name: client name: client
cloud: cloud:
nacos: nacos:
username: nacos
password: nacos
discovery: discovery:
server-addr: localhost:8848 server-addr: localhost:8848
config: config:

@ -6,6 +6,8 @@ spring:
name: configserver name: configserver
cloud: cloud:
nacos: nacos:
username: nacos
password: nacos
discovery: discovery:
server-addr: localhost:8848 server-addr: localhost:8848
config: config:

@ -3,4 +3,7 @@ server.port=18083
management.endpoints.web.exposure.include=* management.endpoints.web.exposure.include=*
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.username=nacos
spring.cloud.nacos.password=nacos
spring.cloud.loadbalancer.ribbon.enabled=false spring.cloud.loadbalancer.ribbon.enabled=false

@ -1,6 +1,10 @@
server.port=18085 server.port=18085
spring.application.name=service-gateway spring.application.name=service-gateway
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.username=nacos
spring.cloud.nacos.password=nacos
management.endpoints.web.exposure.include=* management.endpoints.web.exposure.include=*
# spring cloud route config # spring cloud route config

@ -1,4 +1,8 @@
server.port=18086 server.port=18086
spring.application.name=service-gateway-provider spring.application.name=service-gateway-provider
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.username=nacos
spring.cloud.nacos.password=nacos
management.endpoints.web.exposure.include=* management.endpoints.web.exposure.include=*

@ -47,15 +47,16 @@ import static com.alibaba.nacos.api.PropertyKeyConst.ACCESS_KEY;
import static com.alibaba.nacos.api.PropertyKeyConst.CLUSTER_NAME; import static com.alibaba.nacos.api.PropertyKeyConst.CLUSTER_NAME;
import static com.alibaba.nacos.api.PropertyKeyConst.CONFIG_LONG_POLL_TIMEOUT; import static com.alibaba.nacos.api.PropertyKeyConst.CONFIG_LONG_POLL_TIMEOUT;
import static com.alibaba.nacos.api.PropertyKeyConst.CONFIG_RETRY_TIME; import static com.alibaba.nacos.api.PropertyKeyConst.CONFIG_RETRY_TIME;
import static com.alibaba.nacos.api.PropertyKeyConst.CONTEXT_PATH;
import static com.alibaba.nacos.api.PropertyKeyConst.ENABLE_REMOTE_SYNC_CONFIG; import static com.alibaba.nacos.api.PropertyKeyConst.ENABLE_REMOTE_SYNC_CONFIG;
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.ENDPOINT_PORT;
import static com.alibaba.nacos.api.PropertyKeyConst.MAX_RETRY; import static com.alibaba.nacos.api.PropertyKeyConst.MAX_RETRY;
import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE; import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE;
import static com.alibaba.nacos.api.PropertyKeyConst.PASSWORD;
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;
import static com.alibaba.nacos.api.PropertyKeyConst.USERNAME;
/** /**
* Nacos properties. * Nacos properties.
@ -107,6 +108,14 @@ public class NacosConfigProperties {
} }
this.setServerAddr(serverAddr); this.setServerAddr(serverAddr);
} }
if (StringUtils.isEmpty(this.getUsername())) {
this.setUsername(
environment.resolvePlaceholders("${spring.cloud.nacos.username:}"));
}
if (StringUtils.isEmpty(this.getPassword())) {
this.setPassword(
environment.resolvePlaceholders("${spring.cloud.nacos.password:}"));
}
} }
/** /**
@ -114,6 +123,16 @@ public class NacosConfigProperties {
*/ */
private String serverAddr; private String serverAddr;
/**
* the nacos authentication username.
*/
private String username;
/**
* the nacos authentication password.
*/
private String password;
/** /**
* encode for nacos config content. * encode for nacos config content.
*/ */
@ -226,6 +245,22 @@ public class NacosConfigProperties {
this.serverAddr = serverAddr; this.serverAddr = serverAddr;
} }
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getPrefix() { public String getPrefix() {
return prefix; return prefix;
} }
@ -509,11 +544,12 @@ public class NacosConfigProperties {
public Properties assembleConfigServiceProperties() { public Properties assembleConfigServiceProperties() {
Properties properties = new Properties(); Properties properties = new Properties();
properties.put(SERVER_ADDR, Objects.toString(this.serverAddr, "")); properties.put(SERVER_ADDR, Objects.toString(this.serverAddr, ""));
properties.put(USERNAME, Objects.toString(this.username, ""));
properties.put(PASSWORD, Objects.toString(this.password, ""));
properties.put(ENCODE, Objects.toString(this.encode, "")); properties.put(ENCODE, Objects.toString(this.encode, ""));
properties.put(NAMESPACE, Objects.toString(this.namespace, "")); properties.put(NAMESPACE, Objects.toString(this.namespace, ""));
properties.put(ACCESS_KEY, Objects.toString(this.accessKey, "")); properties.put(ACCESS_KEY, Objects.toString(this.accessKey, ""));
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(CLUSTER_NAME, Objects.toString(this.clusterName, "")); properties.put(CLUSTER_NAME, Objects.toString(this.clusterName, ""));
properties.put(MAX_RETRY, Objects.toString(this.maxRetry, "")); properties.put(MAX_RETRY, Objects.toString(this.maxRetry, ""));
properties.put(CONFIG_LONG_POLL_TIMEOUT, properties.put(CONFIG_LONG_POLL_TIMEOUT,

@ -67,6 +67,28 @@
"type": "java.lang.Boolean", "type": "java.lang.Boolean",
"defaultValue": true, "defaultValue": true,
"description": "enable nacos config or not." "description": "enable nacos config or not."
},
{
"name": "spring.cloud.nacos.config.username",
"type": "java.lang.String",
"defaultValue": "${spring.cloud.nacos.username}",
"description": "nacos config service's userName to authenticate."
},
{
"name": "spring.cloud.nacos.config.password",
"type": "java.lang.String",
"defaultValue": "${spring.cloud.nacos.password}",
"description": "nacos config service's password to authenticate."
},
{
"name": "spring.cloud.nacos.username",
"type": "java.lang.String",
"description": "nacos userName to authenticate."
},
{
"name": "spring.cloud.nacos.password",
"type": "java.lang.String",
"description": "nacos password to authenticate."
} }
] ]
} }

@ -54,8 +54,10 @@ import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT;
import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT_PORT; 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.NAMING_LOAD_CACHE_AT_START; import static com.alibaba.nacos.api.PropertyKeyConst.NAMING_LOAD_CACHE_AT_START;
import static com.alibaba.nacos.api.PropertyKeyConst.PASSWORD;
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;
import static com.alibaba.nacos.api.PropertyKeyConst.USERNAME;
/** /**
* @author dungu.zpf * @author dungu.zpf
@ -82,6 +84,16 @@ public class NacosDiscoveryProperties {
*/ */
private String serverAddr; private String serverAddr;
/**
* the nacos authentication username.
*/
private String username;
/**
* the nacos authentication password.
*/
private String password;
/** /**
* the domain name of a service, through which the server address can be dynamically * the domain name of a service, through which the server address can be dynamically
* obtained. * obtained.
@ -419,6 +431,22 @@ public class NacosDiscoveryProperties {
this.group = group; this.group = group;
} }
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override @Override
public String toString() { public String toString() {
return "NacosDiscoveryProperties{" + "serverAddr='" + serverAddr + '\'' return "NacosDiscoveryProperties{" + "serverAddr='" + serverAddr + '\''
@ -474,6 +502,12 @@ public class NacosDiscoveryProperties {
this.setGroup( this.setGroup(
env.resolvePlaceholders("${spring.cloud.nacos.discovery.group:}")); env.resolvePlaceholders("${spring.cloud.nacos.discovery.group:}"));
} }
if (StringUtils.isEmpty(this.getUsername())) {
this.setUsername(env.resolvePlaceholders("${spring.cloud.nacos.username:}"));
}
if (StringUtils.isEmpty(this.getPassword())) {
this.setPassword(env.resolvePlaceholders("${spring.cloud.nacos.password:}"));
}
} }
public NamingService namingServiceInstance() { public NamingService namingServiceInstance() {
@ -513,6 +547,8 @@ public class NacosDiscoveryProperties {
private Properties getNacosProperties() { private Properties getNacosProperties() {
Properties properties = new Properties(); Properties properties = new Properties();
properties.put(SERVER_ADDR, serverAddr); properties.put(SERVER_ADDR, serverAddr);
properties.put(USERNAME, Objects.toString(username,""));
properties.put(PASSWORD, Objects.toString(password,""));
properties.put(NAMESPACE, namespace); properties.put(NAMESPACE, namespace);
properties.put(UtilAndComs.NACOS_NAMING_LOG_NAME, logName); properties.put(UtilAndComs.NACOS_NAMING_LOG_NAME, logName);

@ -34,5 +34,27 @@
"type": "java.lang.Boolean", "type": "java.lang.Boolean",
"defaultValue": "true", "defaultValue": "true",
"description": "enable nacos discovery watch or not ." "description": "enable nacos discovery watch or not ."
},
{
"name": "spring.cloud.nacos.discovery.username",
"type": "java.lang.String",
"defaultValue": "${spring.cloud.nacos.username}",
"description": "nacos discovery service's username to authenticate."
},
{
"name": "spring.cloud.nacos.discovery.password",
"type": "java.lang.String",
"defaultValue": "${spring.cloud.nacos.password}",
"description": "nacos discovery service's password to authenticate."
},
{
"name": "spring.cloud.nacos.username",
"type": "java.lang.String",
"description": "nacos userName to authenticate."
},
{
"name": "spring.cloud.nacos.password",
"type": "java.lang.String",
"description": "nacos password to authenticate."
} }
]} ]}

Loading…
Cancel
Save