diff --git a/naming/src/main/java/com/alibaba/nacos/naming/constants/FieldsConstants.java b/naming/src/main/java/com/alibaba/nacos/naming/constants/FieldsConstants.java index 6f6f03de0..d67d2ef03 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/constants/FieldsConstants.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/constants/FieldsConstants.java @@ -45,4 +45,14 @@ public class FieldsConstants { public static final String HEALTH_CHECKER = "healthChecker"; + public static final String IP = "ip"; + + public static final String PORT = "port"; + + public static final String CLUSTER_NAME = "clusterName"; + + public static final String SERVICE_NAME = "serviceName"; + + public static final String EPHEMERAL = "ephemeral"; + } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/ClientBeatCheckTask.java b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/ClientBeatCheckTask.java index a3b882c24..4afd2d51f 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/ClientBeatCheckTask.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/ClientBeatCheckTask.java @@ -21,6 +21,7 @@ import com.alibaba.nacos.common.model.RestResult; import com.alibaba.nacos.common.utils.InternetAddressUtil; import com.alibaba.nacos.common.utils.JacksonUtils; import com.alibaba.nacos.naming.consistency.KeyBuilder; +import com.alibaba.nacos.naming.constants.FieldsConstants; import com.alibaba.nacos.naming.core.DistroMapper; import com.alibaba.nacos.naming.core.Instance; import com.alibaba.nacos.naming.core.Service; @@ -48,6 +49,8 @@ public class ClientBeatCheckTask implements BeatCheckTask { private Service service; + public static final String EPHEMERAL = "true"; + public ClientBeatCheckTask(Service service) { this.service = service; } @@ -138,12 +141,16 @@ public class ClientBeatCheckTask implements BeatCheckTask { try { NamingProxy.Request request = NamingProxy.Request.newRequest(); - request.appendParam("ip", instance.getIp()).appendParam("port", String.valueOf(instance.getPort())) - .appendParam("ephemeral", "true").appendParam("clusterName", instance.getClusterName()) - .appendParam("serviceName", service.getName()).appendParam("namespaceId", service.getNamespaceId()); + request.appendParam(FieldsConstants.IP, instance.getIp()) + .appendParam(FieldsConstants.PORT, String.valueOf(instance.getPort())) + .appendParam(FieldsConstants.EPHEMERAL, EPHEMERAL) + .appendParam(FieldsConstants.CLUSTER_NAME, instance.getClusterName()) + .appendParam(FieldsConstants.SERVICE_NAME, service.getName()) + .appendParam(FieldsConstants.NAME_SPACE_ID, service.getNamespaceId()); - String url = "http://" + InternetAddressUtil.localHostIP() + InternetAddressUtil.IP_PORT_SPLITER + EnvUtil.getPort() + EnvUtil - .getContextPath() + UtilsAndCommons.NACOS_NAMING_CONTEXT + "/instance?" + request.toUrl(); + String url = "http://" + InternetAddressUtil.localHostIP() + InternetAddressUtil.IP_PORT_SPLITER + EnvUtil + .getPort() + EnvUtil.getContextPath() + UtilsAndCommons.NACOS_NAMING_CONTEXT + + UtilsAndCommons.NACOS_NAMING_INSTANCE_CONTEXT + "?" + request.toUrl(); // delete instance asynchronously: HttpClient.asyncHttpDelete(url, null, null, new Callback() { diff --git a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/ClientBeatProcessor.java b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/ClientBeatProcessor.java index 259ada57f..53070e88e 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/ClientBeatProcessor.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/ClientBeatProcessor.java @@ -27,7 +27,6 @@ import com.alibaba.nacos.naming.push.UdpPushService; import com.fasterxml.jackson.annotation.JsonIgnore; import java.util.List; -import java.util.concurrent.TimeUnit; /** * Thread to update ephemeral instance triggered by client beat for v1.x. @@ -36,8 +35,6 @@ import java.util.concurrent.TimeUnit; */ public class ClientBeatProcessor implements BeatProcessor { - public static final long CLIENT_BEAT_TIMEOUT = TimeUnit.SECONDS.toMillis(15); - private RsInfo rsInfo; private Service service; diff --git a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/heartbeat/ClientBeatProcessorV2.java b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/heartbeat/ClientBeatProcessorV2.java index 632965bd0..cdc8edfff 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/heartbeat/ClientBeatProcessorV2.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/heartbeat/ClientBeatProcessorV2.java @@ -59,7 +59,7 @@ public class ClientBeatProcessorV2 implements BeatProcessor { HealthCheckInstancePublishInfo instance = (HealthCheckInstancePublishInfo) client.getInstancePublishInfo(service); if (instance.getIp().equals(ip) && instance.getPort() == port) { if (Loggers.EVT_LOG.isDebugEnabled()) { - Loggers.EVT_LOG.debug("[CLIENT-BEAT] refresh beat: {}", rsInfo.toString()); + Loggers.EVT_LOG.debug("[CLIENT-BEAT] refresh beat: {}", rsInfo); } instance.setLastHeartBeatTime(System.currentTimeMillis()); if (!instance.isHealthy()) {