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:
commit
36a4cc9c08
@ -155,6 +155,21 @@ public class NacosDiscoveryProperties {
|
|||||||
*/
|
*/
|
||||||
private String secretKey;
|
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
|
@Autowired
|
||||||
private InetUtils inetUtils;
|
private InetUtils inetUtils;
|
||||||
|
|
||||||
@ -339,6 +354,30 @@ public class NacosDiscoveryProperties {
|
|||||||
this.secretKey = secretKey;
|
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() {
|
public String getNamingLoadCacheAtStart() {
|
||||||
return namingLoadCacheAtStart;
|
return namingLoadCacheAtStart;
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ import org.springframework.util.StringUtils;
|
|||||||
|
|
||||||
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
|
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
|
||||||
import com.alibaba.nacos.api.naming.NamingService;
|
import com.alibaba.nacos.api.naming.NamingService;
|
||||||
|
import com.alibaba.nacos.api.naming.PreservedMetadataKeys;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author xiaojing
|
* @author xiaojing
|
||||||
@ -76,6 +77,19 @@ public class NacosRegistration implements Registration, ServiceInstance {
|
|||||||
metadata.put(MANAGEMENT_ADDRESS, address);
|
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
|
@Override
|
||||||
|
@ -56,7 +56,10 @@ import com.alibaba.cloud.nacos.endpoint.NacosDiscoveryEndpoint;
|
|||||||
"spring.cloud.nacos.discovery.namingLoadCacheAtStart=true",
|
"spring.cloud.nacos.discovery.namingLoadCacheAtStart=true",
|
||||||
"spring.cloud.nacos.discovery.secure=true",
|
"spring.cloud.nacos.discovery.secure=true",
|
||||||
"spring.cloud.nacos.discovery.accessKey=test-accessKey",
|
"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 {
|
public class NacosAutoServiceRegistrationTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -92,6 +95,9 @@ public class NacosAutoServiceRegistrationTests {
|
|||||||
checkoutNacosDiscoverySecure();
|
checkoutNacosDiscoverySecure();
|
||||||
checkoutNacosDiscoveryAccessKey();
|
checkoutNacosDiscoveryAccessKey();
|
||||||
checkoutNacosDiscoverySecrectKey();
|
checkoutNacosDiscoverySecrectKey();
|
||||||
|
checkoutNacosDiscoveryHeartBeatInterval();
|
||||||
|
checkoutNacosDiscoveryHeartBeatTimeout();
|
||||||
|
checkoutNacosDiscoveryIpDeleteTimeout();
|
||||||
|
|
||||||
checkoutNacosDiscoveryServiceName();
|
checkoutNacosDiscoveryServiceName();
|
||||||
checkoutNacosDiscoveryServiceIP();
|
checkoutNacosDiscoveryServiceIP();
|
||||||
@ -162,6 +168,21 @@ public class NacosAutoServiceRegistrationTests {
|
|||||||
properties.getSecretKey());
|
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() {
|
private void checkoutNacosDiscoveryServiceName() {
|
||||||
assertEquals("NacosDiscoveryProperties service name was wrong", "myTestService1",
|
assertEquals("NacosDiscoveryProperties service name was wrong", "myTestService1",
|
||||||
properties.getService());
|
properties.getService());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user