divyanayan
divyanayan

Reputation: 55

Actuator Healthcheck for Third party APIs

Suppose I have an API which calls another API and I want to have a health check of this endpoint as well. Is this possible with Actuator or do I need to write custom code?

Upvotes: 1

Views: 836

Answers (1)

Sukhpal Singh
Sukhpal Singh

Reputation: 2280

You can implement custom health indicator by implementing org.springframework.boot.actuate.health.HealthIndicator and adding it as bean in spring context. Something like below should get you started:

@Component
public class CustomHealthCheck implements HealthIndicator {

    @Override
    public Health health() {
        int errorCode = check();
        if (errorCode != 0) {
            return Health.down()
              .withDetail("Error Code", errorCode).build();
        }
        return Health.up().build();
    }

    public int check() {
        // Custom logic to check health
        return 0;
    }
}

Upvotes: 1

Related Questions