fix:fix heartbeat interval different configuration from polaris-java SDK. (#560)

pull/562/head
Haotian Zhang 2 years ago committed by GitHub
parent 3bf8055e1c
commit d70b945d49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -23,3 +23,4 @@
- [optimizeadd switch for report call result and default false](https://github.com/Tencent/spring-cloud-tencent/pull/547)
- [Optimize: refresh @Value by reflect and only refresh affected ConfigurationProperties beans](https://github.com/Tencent/spring-cloud-tencent/pull/548)
- [feature:remove ConditionalOnConfigReflectEnabled annotation.](https://github.com/Tencent/spring-cloud-tencent/pull/551)
- [fix:fix heartbeat interval different configuration from polaris-java SDK.](https://github.com/Tencent/spring-cloud-tencent/pull/560)

@ -98,11 +98,11 @@ public class PolarisDiscoveryProperties {
private Boolean heartbeatEnabled = true;
/**
* Heart beat interval (The time interval must be greater than zone).
* Time unit: millisecond. Default: 5000.
* Heartbeat interval ( 0 < interval <= 60).
* Time unit: second. Default: 5.
* @see ContextConstant#DEFAULT_REGISTRY_HEARTBEAT_TIME_INTERVAL
*/
private Integer heartbeatInterval = 5000;
private Integer heartbeatInterval = DEFAULT_REGISTRY_HEARTBEAT_TIME_INTERVAL;
/**
* Custom health check url to override default.
@ -212,8 +212,8 @@ public class PolarisDiscoveryProperties {
}
public Integer getHeartbeatInterval() {
if (this.heartbeatEnabled && this.heartbeatInterval <= 0) {
return DEFAULT_REGISTRY_HEARTBEAT_TIME_INTERVAL;
if (this.heartbeatEnabled && (this.heartbeatInterval <= 0 || this.heartbeatInterval > 60)) {
heartbeatInterval = DEFAULT_REGISTRY_HEARTBEAT_TIME_INTERVAL;
}
return heartbeatInterval;
}
@ -273,6 +273,5 @@ public class PolarisDiscoveryProperties {
public int getOrder() {
return ContextConstant.ModifierOrder.LAST;
}
}
}

@ -41,7 +41,7 @@ import org.springframework.beans.BeanUtils;
import org.springframework.cloud.client.serviceregistry.Registration;
import org.springframework.cloud.client.serviceregistry.ServiceRegistry;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.springframework.util.ReflectionUtils.rethrowRuntimeException;
/**
@ -69,8 +69,8 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
this.staticMetadataManager = staticMetadataManager;
if (polarisDiscoveryProperties.isHeartbeatEnabled()) {
this.heartbeatExecutor = Executors.newSingleThreadScheduledExecutor(
new NamedThreadFactory("spring-cloud-heartbeat"));
this.heartbeatExecutor = Executors
.newSingleThreadScheduledExecutor(new NamedThreadFactory("polaris-heartbeat"));
}
else {
this.heartbeatExecutor = null;
@ -207,13 +207,14 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
}
polarisDiscoveryHandler.getProviderAPI().heartbeat(heartbeatRequest);
LOGGER.trace("Polaris heartbeat is sent");
}
catch (PolarisException e) {
LOGGER.error("polaris heartbeat[{}]", e.getCode(), e);
LOGGER.error("polaris heartbeat error with code [{}]", e.getCode(), e);
}
catch (Exception e) {
LOGGER.error("polaris heartbeat runtime error", e);
}
}, polarisDiscoveryProperties.getHeartbeatInterval(), polarisDiscoveryProperties.getHeartbeatInterval(), MILLISECONDS);
}, polarisDiscoveryProperties.getHeartbeatInterval(), polarisDiscoveryProperties.getHeartbeatInterval(), SECONDS);
}
}

@ -27,8 +27,8 @@
{
"name": "spring.cloud.polaris.discovery.heartbeat-interval",
"type": "java.lang.Integer",
"defaultValue": "5000",
"description": "Millis interval of Heart beat. Default: 5000."
"defaultValue": "5",
"description": "Seconds interval of Heart beat. Default: 5."
},
{
"name": "spring.cloud.polaris.discovery.health-check-url",

@ -42,8 +42,12 @@ public class PolarisDiscoveryPropertiesTest {
assertThat(polarisDiscoveryProperties.isHeartbeatEnabled()).isTrue();
// HeartbeatEnabled
polarisDiscoveryProperties.setHeartbeatInterval(2000);
assertThat(polarisDiscoveryProperties.getHeartbeatInterval()).isEqualTo(2000);
polarisDiscoveryProperties.setHeartbeatInterval(200);
assertThat(polarisDiscoveryProperties.getHeartbeatInterval()).isEqualTo(5);
polarisDiscoveryProperties.setHeartbeatInterval(0);
assertThat(polarisDiscoveryProperties.getHeartbeatInterval()).isEqualTo(5);
polarisDiscoveryProperties.setHeartbeatInterval(20);
assertThat(polarisDiscoveryProperties.getHeartbeatInterval()).isEqualTo(20);
// Namespace
polarisDiscoveryProperties.setNamespace(NAMESPACE_TEST);
@ -100,7 +104,7 @@ public class PolarisDiscoveryPropertiesTest {
+ ", enabled=true"
+ ", registerEnabled=true"
+ ", heartbeatEnabled=true"
+ ", heartbeatInterval=2000"
+ ", heartbeatInterval=20"
+ ", healthCheckUrl='/health'"
+ ", serviceListRefreshInterval=1000}");
}

@ -37,9 +37,9 @@ public final class ContextConstant {
public static final String UTF_8 = StandardCharsets.UTF_8.name();
/**
* Default registry heartbeat time interval, default: 5000 (ms).
* Default registry heartbeat time interval: 5 (s).
*/
public static final Integer DEFAULT_REGISTRY_HEARTBEAT_TIME_INTERVAL = 5000;
public static final Integer DEFAULT_REGISTRY_HEARTBEAT_TIME_INTERVAL = 5;
private ContextConstant() {
}

Loading…
Cancel
Save