2

Suppose I have Spring Boot service A which depends on (calls) Spring Boot service B.

A -> B

Spring Boot Actuators can tell me if A is up.

https://A/health

What I want to know is if B is up, by calling A.

https://A/integratedhealth

My question is: Is there a standard way in Spring Boot Actuators of checking the health of child services? (or do I just have to build a custom actuator service?)

4

1 回答 1

1

Spring Boot 提供了很多开箱即用的健康指标。HealthIndicator但是,您可以通过实现接口(ReactiveHealthIndicator对于反应式应用程序)添加自己的自定义健康指标:

@Component
public class ServiceBHealthIndicator implements HealthIndicator {
    
    private final String message_key = "Service B";

    @Override
    public Health health() {
        if (!isRunningServiceB()) {
            return Health.down().withDetail(message_key, "Not Available").build();
        }
        return Health.up().withDetail(message_key, "Available").build();
    }
    private Boolean isRunningServiceB() {
        Boolean isRunning = true;
        // Your logic here
        return isRunning;
    }
}

如果您将其与之前的其他健康指标结合使用,您可以通过以下方式获得健康端点响应:

{
   "status":"DOWN",
   "details":{
      "serviceB":{
         "status":"UP",
         "details":{
            "Service B":"Available"
         }
      },
      "serviceC":{
         "status":"DOWN",
         "details":{
            "Service C":"Not Available"
         }
      }
   }
}

您可以在 Spring Boot 文档中找到有关自定义健康检查端点的更多信息。

于 2020-08-14T06:20:33.993 回答