Skip to content

Commit

Permalink
Merge pull request #1488 from zkzlx/nacos-register
Browse files Browse the repository at this point in the history
[enhance issue #1478 ]支持注册非活动节点
  • Loading branch information
yuhuangbin committed Jul 24, 2020
2 parents f6fb689 + 940420b commit f9f3bd8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
Expand Up @@ -33,6 +33,7 @@ spring:
enabled: true
register-enabled: true
server-addr: 127.0.0.1:8848
ephemeral: false


---
Expand Down
Expand Up @@ -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;

Expand Down Expand Up @@ -461,6 +466,14 @@ public void setInstanceEnabled(boolean instanceEnabled) {
this.instanceEnabled = instanceEnabled;
}

public boolean isEphemeral() {
return ephemeral;
}

public void setEphemeral(boolean ephemeral) {
this.ephemeral = ephemeral;
}

@Override
public String toString() {
return "NacosDiscoveryProperties{" + "serverAddr='" + serverAddr + '\''
Expand Down
Expand Up @@ -95,6 +95,7 @@ public static ServiceInstance hostToServiceInstance(Instance instance,
if (instance.getMetadata() != null) {
metadata.putAll(instance.getMetadata());
}
metadata.put("nacos.ephemeral",String.valueOf(instance.isEphemeral()));
nacosServiceInstance.setMetadata(metadata);

if (metadata.containsKey("secure")) {
Expand Down
Expand Up @@ -161,7 +161,7 @@ private Instance getNacosInstanceFromRegistration(Registration registration) {
instance.setClusterName(nacosDiscoveryProperties.getClusterName());
instance.setEnabled(nacosDiscoveryProperties.isInstanceEnabled());
instance.setMetadata(registration.getMetadata());

instance.setEphemeral(nacosDiscoveryProperties.isEphemeral());
return instance;
}

Expand Down
Expand Up @@ -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",
Expand Down

0 comments on commit f9f3bd8

Please sign in to comment.