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