1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

[Issues] 765 Support customized beat interval of Nacos client

This commit is contained in:
ly 2019-07-18 22:28:46 +08:00
parent 5cf28cb7a6
commit d332ae666b
3 changed files with 75 additions and 1 deletions

View File

@ -142,6 +142,21 @@ public class NacosDiscoveryProperties {
*/
private String secretKey;
/**
* Heart beat interval. Time unit: second.
*/
private Integer heartBeatInterval;
/**
* Heart beat timeout. Time unit: second.
*/
private Integer heartBeatTimeout;
/**
* Ip delete timeout. Time unit: second.
*/
private Integer ipDeleteTimeout;
@Autowired
private InetUtils inetUtils;
@ -326,6 +341,30 @@ public class NacosDiscoveryProperties {
this.secretKey = secretKey;
}
public Integer getHeartBeatInterval() {
return heartBeatInterval;
}
public void setHeartBeatInterval(Integer heartBeatInterval) {
this.heartBeatInterval = heartBeatInterval;
}
public Integer getHeartBeatTimeout() {
return heartBeatTimeout;
}
public void setHeartBeatTimeout(Integer heartBeatTimeout) {
this.heartBeatTimeout = heartBeatTimeout;
}
public Integer getIpDeleteTimeout() {
return ipDeleteTimeout;
}
public void setIpDeleteTimeout(Integer ipDeleteTimeout) {
this.ipDeleteTimeout = ipDeleteTimeout;
}
public String getNamingLoadCacheAtStart() {
return namingLoadCacheAtStart;
}

View File

@ -16,6 +16,7 @@
package com.alibaba.cloud.nacos.registry;
import com.alibaba.nacos.api.naming.PreservedMetadataKeys;
import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.ManagementServerPortUtils;
@ -76,6 +77,19 @@ public class NacosRegistration implements Registration, ServiceInstance {
metadata.put(MANAGEMENT_ADDRESS, address);
}
}
if (null != nacosDiscoveryProperties.getHeartBeatInterval()) {
metadata.put(PreservedMetadataKeys.HEART_BEAT_INTERVAL,
nacosDiscoveryProperties.getHeartBeatInterval().toString());
}
if (null != nacosDiscoveryProperties.getHeartBeatTimeout()) {
metadata.put(PreservedMetadataKeys.HEART_BEAT_TIMEOUT,
nacosDiscoveryProperties.getHeartBeatTimeout().toString());
}
if (null != nacosDiscoveryProperties.getIpDeleteTimeout()) {
metadata.put(PreservedMetadataKeys.IP_DELETE_TIMEOUT,
nacosDiscoveryProperties.getIpDeleteTimeout().toString());
}
}
@Override

View File

@ -56,7 +56,10 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
"spring.cloud.nacos.discovery.namingLoadCacheAtStart=true",
"spring.cloud.nacos.discovery.secure=true",
"spring.cloud.nacos.discovery.accessKey=test-accessKey",
"spring.cloud.nacos.discovery.secretKey=test-secretKey" }, webEnvironment = RANDOM_PORT)
"spring.cloud.nacos.discovery.secretKey=test-secretKey",
"spring.cloud.nacos.discovery.heart-beat-interval=3",
"spring.cloud.nacos.discovery.heart-beat-timeout=6",
"spring.cloud.nacos.discovery.ip-delete-timeout=9", }, webEnvironment = RANDOM_PORT)
public class NacosAutoServiceRegistrationTests {
@Autowired
@ -92,6 +95,9 @@ public class NacosAutoServiceRegistrationTests {
checkoutNacosDiscoverySecure();
checkoutNacosDiscoveryAccessKey();
checkoutNacosDiscoverySecrectKey();
checkoutNacosDiscoveryHeartBeatInterval();
checkoutNacosDiscoveryHeartBeatTimeout();
checkoutNacosDiscoveryIpDeleteTimeout();
checkoutNacosDiscoveryServiceName();
checkoutNacosDiscoveryServiceIP();
@ -162,6 +168,21 @@ public class NacosAutoServiceRegistrationTests {
properties.getSecretKey());
}
private void checkoutNacosDiscoveryHeartBeatInterval() {
assertEquals("NacosDiscoveryProperties heart beat interval was wrong", Integer.valueOf(3),
properties.getHeartBeatInterval());
}
private void checkoutNacosDiscoveryHeartBeatTimeout() {
assertEquals("NacosDiscoveryProperties heart beat timeout was wrong", Integer.valueOf(6),
properties.getHeartBeatInterval());
}
private void checkoutNacosDiscoveryIpDeleteTimeout() {
assertEquals("NacosDiscoveryProperties ip delete timeout was wrong", Integer.valueOf(9),
properties.getHeartBeatInterval());
}
private void checkoutNacosDiscoveryServiceName() {
assertEquals("NacosDiscoveryProperties service name was wrong", "myTestService1",
properties.getService());