Health check (Spring Cloud SOFA Health)
Spring Cloud SOFA extends the Spring Boot health check with a Readiness Check. This feature checks the built-in components of Spring Cloud SOFA to confirm that the application is ready.
Spring Cloud SOFA Registry is associated with the Readiness Check. By default, it registers services only after the application passes the check. This process ensures the graceful publishing of microservices. The Readiness Check can also be used by a Platform as a Service (PaaS) platform to check applications. It can be combined with the Kubernetes (K8s) Readiness probe to achieve graceful publishing at the PaaS layer.
Adding the health check
Add the Spring Cloud SOFA Health dependency to your project without specifying a version. The version is managed by dependencyManagement.
<dependency>
<groupId>com.alipay.cloud</groupId>
<artifactId>spring-cloud-starter-sofa-health</artifactId>
</dependency>If you add components that use the SOFA health check to your project, such as Spring Cloud SOFA Registry or Spring Cloud SOFA DRM, Spring Cloud SOFA Health is automatically included. You do not need to add the dependency manually.
Custom Readiness Check
The Spring Cloud SOFA health check module provides a new set of interfaces for creating custom Readiness Checks and defining associated actions that run after the application is ready.
Callback interface | Description |
com.alipay.cloud.healthcheck.core.HealthChecker | To add a check item to the Spring Cloud SOFA Readiness Check, extend this interface. Compared to the standard Spring Boot HealthIndicator interface, this interface provides additional parameter settings, such as the number of retries after a failed check. |
com.alipay.cloud.healthcheck.startup.ReadinessCheckCallback | To perform actions after the Readiness Check is complete, extend this SOFABoot interface. |
The Spring Cloud SOFA Readiness Check also includes native Spring Boot health checks as check items. You can also add check items through Spring Boot extension interfaces. However, the Spring Boot health check focuses on instantaneous states and lacks logic for features such as retries. Therefore, do not use Spring Boot to extend Readiness Check items for actions that are not guaranteed to be ready before the application finishes starting.
Callback interface | Description |
org.springframework.boot.actuate.health.HealthIndicator | To add a check item to the Spring Cloud SOFA Readiness Check, extend this Spring Boot interface. |
org.springframework.boot.actuate.health.ReactiveHealthIndicator | In WebFlux, to add a check item to the Spring Cloud SOFA Readiness Check, extend this Spring Boot interface. |
You can set the execution order for the four preceding extension interfaces using the standard Spring Boot Ordered, PriorityOrdered, and the @Order annotation.
Implement these interfaces and load them as Spring Beans into the Spring container context to activate them.