Merge pull request #54 from lepdou/feature/optimize_heartbeat

send heartbeat if healthcheck url not configured
pull/59/head
Haotian Zhang 3 years ago committed by GitHub
commit 75d4eb9a31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -177,22 +177,28 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
* @param heartbeatRequest
*/
public void heartbeat(InstanceHeartbeatRequest heartbeatRequest) {
heartbeatExecutor.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
try {
String healthCheckUrl = String.format("http://%s:%s%s", heartbeatRequest.getHost(), heartbeatRequest.getPort(), polarisProperties.getHealthCheckUrl());
//先判断是否配置了health-check-url如果配置了需要先进行服务实例健康检查如果健康检查通过则进行心跳上报如果不通过则不上报心跳
if (Strings.isNotEmpty(healthCheckUrl) && !OkHttpUtil.get(healthCheckUrl, null)){
log.error("polaris health check failed");
heartbeatExecutor.scheduleWithFixedDelay(() -> {
try {
String healthCheckEndpoint = polarisProperties.getHealthCheckUrl();
//先判断是否配置了health-check-url如果配置了需要先进行服务实例健康检查如果健康检查通过则进行心跳上报如果不通过则不上报心跳
if (Strings.isNotEmpty(healthCheckEndpoint)) {
if (!healthCheckEndpoint.startsWith("/")) {
healthCheckEndpoint = "/" + healthCheckEndpoint;
}
String healthCheckUrl = String.format("http://%s:%s%s", heartbeatRequest.getHost(), heartbeatRequest.getPort(), healthCheckEndpoint);
if (!OkHttpUtil.get(healthCheckUrl, null)){
log.error("backend service health check failed. health check endpoint = {}", healthCheckEndpoint);
return;
}
polarisDiscoveryHandler.getProviderAPI().heartbeat(heartbeatRequest);
} catch (PolarisException e) {
log.error("polaris heartbeat[{}]", e.getCode(), e);
} catch (Exception e) {
log.error("polaris heartbeat runtime error", e);
}
polarisDiscoveryHandler.getProviderAPI().heartbeat(heartbeatRequest);
} catch (PolarisException e) {
log.error("polaris heartbeat[{}]", e.getCode(), e);
} catch (Exception e) {
log.error("polaris heartbeat runtime error", e);
}
}, 0, ttl, TimeUnit.SECONDS);
}

Loading…
Cancel
Save