mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
commit
5066b92378
@ -415,8 +415,8 @@ Endpoint 暴露的 json 中包含了三种属性:
|
||||
|===
|
||||
|配置项 |Key |默认值 |说明
|
||||
|服务端地址|`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.prefix`|| 先取 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
|
||||
|配置内容编码|`spring.cloud.nacos.config.encode`||读取的配置内容对应的编码
|
||||
|GROUP|`spring.cloud.nacos.config.group`|`DEFAULT_GROUP`|配置对应的组
|
||||
|文件扩展名|`spring.cloud.nacos.config.fileExtension`|`properties`|配置项对应的文件扩展名,目前支持 properties 和 yaml(yml)
|
||||
|
@ -30,7 +30,7 @@
|
||||
public class ProviderApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
SpringApplication.run(ProviderApplication.class, args);
|
||||
}
|
||||
|
||||
@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 static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
SpringApplication.run(ProviderApplication.class, args);
|
||||
}
|
||||
|
||||
@RestController
|
||||
|
@ -33,6 +33,7 @@ spring:
|
||||
enabled: true
|
||||
register-enabled: true
|
||||
server-addr: 127.0.0.1:8848
|
||||
ephemeral: false
|
||||
|
||||
|
||||
---
|
||||
|
@ -204,6 +204,11 @@ public class NacosDiscoveryProperties {
|
||||
*/
|
||||
private boolean instanceEnabled = true;
|
||||
|
||||
/**
|
||||
* If instance is ephemeral.The default value is true.
|
||||
*/
|
||||
private boolean ephemeral = true;
|
||||
|
||||
@Autowired
|
||||
private InetUtils inetUtils;
|
||||
|
||||
@ -461,6 +466,14 @@ public class NacosDiscoveryProperties {
|
||||
this.instanceEnabled = instanceEnabled;
|
||||
}
|
||||
|
||||
public boolean isEphemeral() {
|
||||
return ephemeral;
|
||||
}
|
||||
|
||||
public void setEphemeral(boolean ephemeral) {
|
||||
this.ephemeral = ephemeral;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NacosDiscoveryProperties{" + "serverAddr='" + serverAddr + '\''
|
||||
|
@ -92,7 +92,10 @@ public class NacosServiceDiscovery {
|
||||
metadata.put("nacos.weight", instance.getWeight() + "");
|
||||
metadata.put("nacos.healthy", instance.isHealthy() + "");
|
||||
metadata.put("nacos.cluster", instance.getClusterName() + "");
|
||||
metadata.putAll(instance.getMetadata());
|
||||
if (instance.getMetadata() != null) {
|
||||
metadata.putAll(instance.getMetadata());
|
||||
}
|
||||
metadata.put("nacos.ephemeral",String.valueOf(instance.isEphemeral()));
|
||||
nacosServiceInstance.setMetadata(metadata);
|
||||
|
||||
if (metadata.containsKey("secure")) {
|
||||
|
@ -161,7 +161,7 @@ public class NacosServiceRegistry implements ServiceRegistry<Registration> {
|
||||
instance.setClusterName(nacosDiscoveryProperties.getClusterName());
|
||||
instance.setEnabled(nacosDiscoveryProperties.isInstanceEnabled());
|
||||
instance.setMetadata(registration.getMetadata());
|
||||
|
||||
instance.setEphemeral(nacosDiscoveryProperties.isEphemeral());
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
@ -51,12 +51,13 @@ public class NacosRule extends AbstractLoadBalancerRule {
|
||||
public Server choose(Object key) {
|
||||
try {
|
||||
String clusterName = this.nacosDiscoveryProperties.getClusterName();
|
||||
String group = this.nacosDiscoveryProperties.getGroup();
|
||||
DynamicServerListLoadBalancer loadBalancer = (DynamicServerListLoadBalancer) getLoadBalancer();
|
||||
String name = loadBalancer.getName();
|
||||
|
||||
NamingService namingService = nacosDiscoveryProperties
|
||||
.namingServiceInstance();
|
||||
List<Instance> instances = namingService.selectInstances(name, true);
|
||||
List<Instance> instances = namingService.selectInstances(name, group, true);
|
||||
if (CollectionUtils.isEmpty(instances)) {
|
||||
LOGGER.warn("no instance in service {}", name);
|
||||
return null;
|
||||
|
@ -29,6 +29,12 @@
|
||||
"defaultValue": true,
|
||||
"description": "If instance is enabled to accept request. The default value is true."
|
||||
},
|
||||
{
|
||||
"name": "spring.cloud.nacos.discovery.ephemeral",
|
||||
"type": "java.lang.Boolean",
|
||||
"defaultValue": true,
|
||||
"description": "If instance is ephemeral.The default value is true."
|
||||
},
|
||||
{
|
||||
"name": "spring.cloud.nacos.discovery.namingLoadCacheAtStart",
|
||||
"type": "java.lang.Boolean",
|
||||
|
@ -153,6 +153,7 @@
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -169,7 +169,7 @@ public class RocketMQMessageChannelBinder extends
|
||||
rocketMQTemplate, destination.getName(), producerGroup,
|
||||
producerProperties.getExtension().getTransactional(),
|
||||
instrumentationManager, producerProperties,
|
||||
((AbstractMessageChannel) channel).getChannelInterceptors().stream()
|
||||
((AbstractMessageChannel) channel).getInterceptors().stream()
|
||||
.filter(channelInterceptor -> channelInterceptor instanceof MessageConverterConfigurer.PartitioningInterceptor)
|
||||
.map(channelInterceptor -> ((MessageConverterConfigurer.PartitioningInterceptor) channelInterceptor))
|
||||
.findFirst().orElse(null));
|
||||
|
Loading…
x
Reference in New Issue
Block a user