mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
commit
a8ac85beb9
@ -415,8 +415,8 @@ Endpoint 暴露的 json 中包含了三种属性:
|
|||||||
|===
|
|===
|
||||||
|配置项 |Key |默认值 |说明
|
|配置项 |Key |默认值 |说明
|
||||||
|服务端地址|`spring.cloud.nacos.config.server-addr`|| Nacos Server 启动监听的ip地址和端口
|
|服务端地址|`spring.cloud.nacos.config.server-addr`|| Nacos Server 启动监听的ip地址和端口
|
||||||
|配置对应的 DataId|`spring.cloud.nacos.config.name`|| 先取 prefix,再去 name,最后取 spring.application.name
|
|配置对应的 DataId|`spring.cloud.nacos.config.name`|| 先取 prefix,再取 name,最后取 spring.application.name
|
||||||
|配置对应的 DataId|`spring.cloud.nacos.config.prefix`|| 先取 prefix,再去 name,最后取 spring.application.name
|
|配置对应的 DataId|`spring.cloud.nacos.config.prefix`|| 先取 prefix,再取 name,最后取 spring.application.name
|
||||||
|配置内容编码|`spring.cloud.nacos.config.encode`||读取的配置内容对应的编码
|
|配置内容编码|`spring.cloud.nacos.config.encode`||读取的配置内容对应的编码
|
||||||
|GROUP|`spring.cloud.nacos.config.group`|`DEFAULT_GROUP`|配置对应的组
|
|GROUP|`spring.cloud.nacos.config.group`|`DEFAULT_GROUP`|配置对应的组
|
||||||
|文件扩展名|`spring.cloud.nacos.config.fileExtension`|`properties`|配置项对应的文件扩展名,目前支持 properties 和 yaml(yml)
|
|文件扩展名|`spring.cloud.nacos.config.fileExtension`|`properties`|配置项对应的文件扩展名,目前支持 properties 和 yaml(yml)
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
public class ProviderApplication {
|
public class ProviderApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(Application.class, args);
|
SpringApplication.run(ProviderApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
|
@ -29,7 +29,7 @@ Before we start the demo, let's learn how to connect Nacos Config to a Spring Cl
|
|||||||
public class ProviderApplication {
|
public class ProviderApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(Application.class, args);
|
SpringApplication.run(ProviderApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
|
@ -92,7 +92,9 @@ public class NacosServiceDiscovery {
|
|||||||
metadata.put("nacos.weight", instance.getWeight() + "");
|
metadata.put("nacos.weight", instance.getWeight() + "");
|
||||||
metadata.put("nacos.healthy", instance.isHealthy() + "");
|
metadata.put("nacos.healthy", instance.isHealthy() + "");
|
||||||
metadata.put("nacos.cluster", instance.getClusterName() + "");
|
metadata.put("nacos.cluster", instance.getClusterName() + "");
|
||||||
metadata.putAll(instance.getMetadata());
|
if (instance.getMetadata() != null) {
|
||||||
|
metadata.putAll(instance.getMetadata());
|
||||||
|
}
|
||||||
nacosServiceInstance.setMetadata(metadata);
|
nacosServiceInstance.setMetadata(metadata);
|
||||||
|
|
||||||
if (metadata.containsKey("secure")) {
|
if (metadata.containsKey("secure")) {
|
||||||
|
@ -51,12 +51,13 @@ public class NacosRule extends AbstractLoadBalancerRule {
|
|||||||
public Server choose(Object key) {
|
public Server choose(Object key) {
|
||||||
try {
|
try {
|
||||||
String clusterName = this.nacosDiscoveryProperties.getClusterName();
|
String clusterName = this.nacosDiscoveryProperties.getClusterName();
|
||||||
|
String group = this.nacosDiscoveryProperties.getGroup();
|
||||||
DynamicServerListLoadBalancer loadBalancer = (DynamicServerListLoadBalancer) getLoadBalancer();
|
DynamicServerListLoadBalancer loadBalancer = (DynamicServerListLoadBalancer) getLoadBalancer();
|
||||||
String name = loadBalancer.getName();
|
String name = loadBalancer.getName();
|
||||||
|
|
||||||
NamingService namingService = nacosDiscoveryProperties
|
NamingService namingService = nacosDiscoveryProperties
|
||||||
.namingServiceInstance();
|
.namingServiceInstance();
|
||||||
List<Instance> instances = namingService.selectInstances(name, true);
|
List<Instance> instances = namingService.selectInstances(name, group, true);
|
||||||
if (CollectionUtils.isEmpty(instances)) {
|
if (CollectionUtils.isEmpty(instances)) {
|
||||||
LOGGER.warn("no instance in service {}", name);
|
LOGGER.warn("no instance in service {}", name);
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user