pull/1680/head
Haotian Zhang 1 month ago
parent d1c38d1084
commit 48c8922d28

@ -1,15 +1,6 @@
# Change Log
---
- [fix: add gateway context config example.](https://github.com/Tencent/spring-cloud-tencent/pull/1563)
- [feat:support config empty protection.](https://github.com/Tencent/spring-cloud-tencent/pull/1585)
- [feat:upgrade springframework version.](https://github.com/Tencent/spring-cloud-tencent/pull/1590)
- [feat:support dynamic multi-discovery.](https://github.com/Tencent/spring-cloud-tencent/pull/1595)
- [feat:support ipv6.](https://github.com/Tencent/spring-cloud-tencent/pull/1598)
- [feat:support config all recover enabled.](https://github.com/Tencent/spring-cloud-tencent/pull/1604)
- [feat:support stat reporting path aggregation.](https://github.com/Tencent/spring-cloud-tencent/pull/1608)
- [feat:support instance detect.](https://github.com/Tencent/spring-cloud-tencent/pull/1617)
- [fix: polaris.discovery.heartbeat.enabled not effective.](https://github.com/Tencent/spring-cloud-tencent/pull/1621)
- [fix:fix PolarisContextProperties instantiated twice causing NPE.](https://github.com/Tencent/spring-cloud-tencent/pull/1638)
- [feat:support setting load balancing strategy per service.](https://github.com/Tencent/spring-cloud-tencent/pull/1633)
- [feat: support tsf 2024.](https://github.com/Tencent/spring-cloud-tencent/pull/1635)
@ -25,4 +16,5 @@
- [fix: fix lb configuration on bootstrap step.](https://github.com/Tencent/spring-cloud-tencent/issues/1673)
- [feat:support 2024.0.2.](https://github.com/Tencent/spring-cloud-tencent/issues/1674)
- [feat:support fault injection.](https://github.com/Tencent/spring-cloud-tencent/pull/1672)
- [feat: support config event and monitor address list.](https://github.com/Tencent/spring-cloud-tencent/pull/1675)
- [feat: support config event and monitor address list.](https://github.com/Tencent/spring-cloud-tencent/pull/1675)
- [fix: polaris.discovery.heartbeat.enabled not effective.](https://github.com/Tencent/spring-cloud-tencent/pull/1680)

@ -83,6 +83,11 @@ public class PolarisDiscoveryProperties {
@Value("${spring.cloud.polaris.discovery.register:#{true}}")
private Boolean registerEnabled;
/**
* Enable heartbeat or not.
*/
private Boolean heartbeatEnabled = true;
/**
* Heartbeat interval ( 0 < interval <= 60).
* Time unit: second. Default: 5.
@ -207,7 +212,15 @@ public class PolarisDiscoveryProperties {
public void setServiceListRefreshInterval(Long serviceListRefreshInterval) {
this.serviceListRefreshInterval = serviceListRefreshInterval;
}
public Boolean getHeartbeatEnabled() {
return heartbeatEnabled;
}
public void setHeartbeatEnabled(Boolean heartbeatEnabled) {
this.heartbeatEnabled = heartbeatEnabled;
}
public Integer getHeartbeatInterval() {
if (this.heartbeatInterval <= 0 || this.heartbeatInterval > 60) {
heartbeatInterval = DEFAULT_REGISTRY_HEARTBEAT_TIME_INTERVAL;
@ -291,6 +304,7 @@ public class PolarisDiscoveryProperties {
", protocol='" + protocol + '\'' +
", enabled=" + enabled +
", registerEnabled=" + registerEnabled +
", heartbeatEnabled=" + heartbeatEnabled +
", heartbeatInterval=" + heartbeatInterval +
", healthCheckUrl='" + healthCheckUrl + '\'' +
", serviceListRefreshInterval=" + serviceListRefreshInterval +

@ -127,7 +127,6 @@ public class PolarisServiceRegistry implements ServiceRegistry<PolarisRegistrati
instanceRegisterRequest.setRegion(staticMetadataManager.getRegion());
instanceRegisterRequest.setZone(staticMetadataManager.getZone());
instanceRegisterRequest.setCampus(staticMetadataManager.getCampus());
instanceRegisterRequest.setTtl(polarisDiscoveryProperties.getHeartbeatInterval());
instanceRegisterRequest.setMetadata(registration.getMetadata());
instanceRegisterRequest.setExtendedMetadata(registration.getExtendedMetadata());
instanceRegisterRequest.setProtocol(polarisDiscoveryProperties.getProtocol());
@ -144,16 +143,24 @@ public class PolarisServiceRegistry implements ServiceRegistry<PolarisRegistrati
try {
ProviderAPI providerClient = polarisSDKContextManager.getProviderAPI();
InstanceRegisterResponse instanceRegisterResponse;
if (StringUtils.isBlank(polarisDiscoveryProperties.getHealthCheckUrl())) {
instanceRegisterResponse = providerClient.registerInstance(instanceRegisterRequest);
if (polarisDiscoveryProperties.getHeartbeatEnabled()) {
if (StringUtils.isBlank(polarisDiscoveryProperties.getHealthCheckUrl())) {
instanceRegisterResponse = providerClient.registerInstance(instanceRegisterRequest);
}
else {
instanceRegisterRequest.setTtl(polarisDiscoveryProperties.getHeartbeatInterval());
instanceRegisterResponse = providerClient.register(instanceRegisterRequest);
InstanceHeartbeatRequest heartbeatRequest = new InstanceHeartbeatRequest();
BeanUtils.copyProperties(instanceRegisterRequest, heartbeatRequest);
heartbeatRequest.setInstanceID(instanceRegisterResponse.getInstanceId());
// Start the heartbeat thread after the registration is successful.
heartbeat(heartbeatRequest);
}
}
else {
// Heartbeat is disabled
instanceRegisterResponse = providerClient.register(instanceRegisterRequest);
InstanceHeartbeatRequest heartbeatRequest = new InstanceHeartbeatRequest();
BeanUtils.copyProperties(instanceRegisterRequest, heartbeatRequest);
heartbeatRequest.setInstanceID(instanceRegisterResponse.getInstanceId());
// Start the heartbeat thread after the registration is successful.
heartbeat(heartbeatRequest);
LOGGER.info("Registered instance without heartbeat.");
}
registration.setInstanceId(instanceRegisterResponse.getInstanceId());
LOGGER.info("polaris registry, {} {} {} {}:{} {} {} {} {} register finished", polarisDiscoveryProperties.getNamespace(),

Loading…
Cancel
Save