HealthCheckService

This SPI service integrates with Spring Boot’s HealthIndicator SPI, surfaced through the Spring Boot Actuator.

This is accessible from the /actuator/health endpoint.

The service, when called, will be within the context of a special internal user health with the internal role health-role.

This service was introduced to allow deployment infrastructure to monitor the app and (potentially) restart it if required. For example, if deploying to Docker then both Docker Swarm and Kubernetes are orchestrators that can perform this task.

SPI

The SPI defined by HealthCheckService is:

public interface HealthCheckService {

    Health check();

}

Implementation

The framework provides no default implementation, but the simpleapp starter app provides a sample implementation:

@Service
@Named("domainapp.HealthCheckServiceImpl")
@Log4j2
public class HealthCheckServiceImpl implements HealthCheckService {

    private final SimpleObjects simpleObjects;

    @Inject
    public HealthCheckServiceImpl(SimpleObjects simpleObjects) {
        this.simpleObjects = simpleObjects;
    }

    @Override
    public Health check() {
        try {
            simpleObjects.ping();
            return Health.ok();
        } catch (Exception ex) {
            return Health.error(ex);
        }
    }
}

The internal domain service o.a.i.core.webapp.health.HealthIndicatorUsingHealthCheckService acts as the bridge between Spring and the `HealthCheckService' SPI.