diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistry.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistry.java index 4fc5a8efa..dd9649e9e 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistry.java +++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistry.java @@ -77,7 +77,7 @@ public class PolarisServiceRegistry implements ServiceRegistry { try { - // If the health check passes, the heartbeat will be reported. - // If it does not pass, the heartbeat will not be reported. + // Skip heartbeat if disabled or health check URL is not set + if (!polarisDiscoveryProperties.getHeartbeatEnabled() || + StringUtils.isBlank(polarisDiscoveryProperties.getHealthCheckUrl())) { + return; + } + Map headers = new HashMap<>(1); headers.put(HttpHeaders.USER_AGENT, "polaris"); if (!OkHttpUtil.checkUrl(heartbeatRequest.getHost(), heartbeatRequest.getPort(), diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-a/src/main/resources/application.yml b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-a/src/main/resources/application.yml index 973625425..1fa63d14c 100644 --- a/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-a/src/main/resources/application.yml +++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-a/src/main/resources/application.yml @@ -13,6 +13,8 @@ spring: discovery: enabled: true register: true + heartbeat: + enabled: false contract: exposure: true report: