A wellness check reports application or dependency conditions that may indicate trouble without proving that the process is dead or unable to serve requests. Unlike liveness and readiness checks, it supports monitoring and human investigation without automatically restarting the application or withholding traffic. section 10.2
Use wellness checks when a condition matters operationally but does not justify immediate automated action:
- Report an empty inventory as DOWN even though the Inventory service itself may still be running. section 10.2.1
- Expose less serious problems for custom monitoring tools or manual operators. section 10.2
- Keep liveness, readiness, and startup checks focused on process continuity, traffic acceptance, and initialization. section 10.2
Inventory count check
Implement HealthCheck, annotate the class with SmallRye's @Wellness, query the repository, and set the response status from the result. A car count above zero returns UP; zero returns DOWN. Include the count as response data so operators can see why the status changed. section 10.2.1
Listing 10.3 Wellness check reporting DOWN if the inventory is empty
package org.acme.inventory.health;
import io.smallrye.health.api.Wellness;
import jakarta.inject.Inject;
import org.acme.inventory.repository.CarRepository;
import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;
@Wellness
public class CarCountCheck implements HealthCheck {
@Inject
CarRepository carRepository;
@Override
public HealthCheckResponse call() {
long carsCount = carRepository.findAll().count();
boolean wellnessStatus = carsCount > 0;
return HealthCheckResponse.builder()
.name("car-count-check")
.status(wellnessStatus) #1
.withData("cars-count", carsCount) #2
.build();
}
}
The complete CarCountCheck implementation shows the @Wellness annotation, HealthCheck contract, repository query, status selection, and cars-count diagnostic field. section 10.2.1
Listing 10.5 The wellness check when the inventory is empty
{
"status": "DOWN",
"checks": [
{
"name": "car-count-check",
"status": "DOWN",
"data": {
"cars-count": 0
}
}
]
}
The failing response shows the aggregate DOWN status and the cars-count value of zero when the inventory is empty. section 10.2.1
