Skip to content

Commit

Permalink
[huaweicloud#1276] Nacos registryHelthIndicator compatible graceful s…
Browse files Browse the repository at this point in the history
…cenes microservice health check
  • Loading branch information
chengyouling committed May 24, 2024
1 parent 97cd016 commit b191c5d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.huaweicloud.nacos.discovery.registry.NacosServiceRegistrationEvent;

public class NacosRegistryHealthIndicator implements HealthIndicator {
private boolean isSuccess = false;
private Boolean register;

private static final String REGISTRATION_NOT_READY = "nacos registration not ready";

Expand All @@ -35,14 +35,14 @@ public NacosRegistryHealthIndicator() {

@Override
public Health health() {
if (isSuccess) {
if (register == null || register) {
return Health.up().build();
}
return Health.down().withDetail("Error Message", REGISTRATION_NOT_READY).build();
}

@Subscribe
public void registryListener(NacosServiceRegistrationEvent event) {
this.isSuccess = event.isSuccess();
this.register = event.isSuccess();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import javax.annotation.Nullable;

import org.apache.commons.lang.StringUtils;
import org.apache.servicecomb.service.center.client.model.MicroserviceInstanceStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
Expand Down Expand Up @@ -51,6 +52,8 @@ public void gracefulUpperAndDown(@Nullable String status) {
LOGGER.warn("status input " + status + " is not a valid value.");
return;
}
serviceCombRegistration.getMicroserviceInstance()
.setStatus(MicroserviceInstanceStatus.valueOf(status.toUpperCase()));
serviceCombServiceRegistry.setStatus(serviceCombRegistration, status.toUpperCase());
}
}

0 comments on commit b191c5d

Please sign in to comment.