Is there a standard way in Spring Boot Actuators of checking the health of child services?

Viewed 487

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?)

1 Answers

Spring boot provides a lot of Health Indicators out of the box. However, you can add your own custom health indicator by implementing HealthIndicator interface (ReactiveHealthIndicator for reactive apps):

@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;
    }
}

If you combine it with other health indicators like the one before, you can get a health endpoint response in a way like this:

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

You can find more information about custom health checks and endpoints in the spring boot documentation.

Related