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

Merge pull request #766 from ly641921791/issues765

Fixes #765 Support customized beat interval of Nacos client
This commit is contained in:
format 2019-07-25 16:50:10 +08:00 committed by GitHub
commit 36a4cc9c08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 75 additions and 1 deletions

View File

@ -155,6 +155,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;
@ -339,6 +354,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

@ -31,6 +31,7 @@ import org.springframework.util.StringUtils;
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.PreservedMetadataKeys;
/**
* @author xiaojing
@ -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 com.alibaba.cloud.nacos.endpoint.NacosDiscoveryEndpoint;
"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.getHeartBeatTimeout());
}
private void checkoutNacosDiscoveryIpDeleteTimeout() {
assertEquals("NacosDiscoveryProperties ip delete timeout was wrong",
Integer.valueOf(9), properties.getIpDeleteTimeout());
}
private void checkoutNacosDiscoveryServiceName() {
assertEquals("NacosDiscoveryProperties service name was wrong", "myTestService1",
properties.getService());