Post

Spring Boot: Writing Custom Health Indicators

Spring Boot lets you expose custom health checks using HealthIndicator.

Sample:

1
2
3
4
5
6
7
8
9
10
11
@Component
public class QueueHealthIndicator implements HealthIndicator {
    public Health health() {
        if (queue.isAvailable()) {
            return Health.up().build();
        } else {
            return Health.down().withDetail("queue", "Unavailable").build();
        }
    }
}

Useful for circuit breakers, dashboards, and alerts.

This post is licensed under CC BY 4.0 by the author.