Service Provider Interface (SPI) for SmallRye Health extension in Quarkus - provides build-time integration for health check functionality
npx @tessl/cli install tessl/maven-io-quarkus--quarkus-smallrye-health-spi@3.26.0Service Provider Interface (SPI) for SmallRye Health extension in Quarkus. Provides build-time integration for health check functionality, enabling extensions and applications to register health checks during the Quarkus compilation process.
pom.xml (typically with provided scope for extension development):<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-health-spi</artifactId>
<version>3.26.2</version>
<scope>provided</scope>
</dependency>import io.quarkus.smallrye.health.deployment.spi.HealthBuildItem;For implementing health checks:
import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;import io.quarkus.smallrye.health.deployment.spi.HealthBuildItem;
// Create a build item to register a health check during build time
HealthBuildItem healthItem = new HealthBuildItem(
"com.example.MyHealthCheck",
true
);
// The health check class must implement org.eclipse.microprofile.health.HealthCheck
public class MyHealthCheck implements org.eclipse.microprofile.health.HealthCheck {
@Override
public HealthCheckResponse call() {
return HealthCheckResponse.up("my-service");
}
}This SPI is designed for Quarkus extension developers and follows the Quarkus build-time optimization pattern:
HealthBuildItem extends MultiBuildItem to allow multiple health checks to be registered/q/health, /q/health/live, /q/health/ready)Register health check classes during the Quarkus build phase for inclusion in the final application.
/**
* Build-time item for registering health check classes during Quarkus application compilation.
* Extends MultiBuildItem to allow multiple health checks to be registered.
*
* This class is immutable and thread-safe.
*/
public final class HealthBuildItem extends MultiBuildItem {
/**
* Creates a new HealthBuildItem instance.
*
* @param healthCheckClass the name of the health check class, must implement
* org.eclipse.microprofile.health.HealthCheck
* @param enabled whether the health check is enabled
*/
public HealthBuildItem(String healthCheckClass, boolean enabled);
/**
* Deprecated constructor - use the two-parameter version instead.
*
* @param healthCheckClass the name of the health check class
* @param enabled whether the health check is enabled
* @param configRootName this parameter is not used
* @deprecated Use HealthBuildItem(String, boolean) instead.
*/
@Deprecated
public HealthBuildItem(String healthCheckClass, boolean enabled, String configRootName);
/**
* Returns the name of the health check class.
*
* @return the health check class name (immutable)
*/
public String getHealthCheckClass();
/**
* Returns whether the health check is enabled.
*
* @return true if the health check is enabled, false otherwise
*/
public boolean isEnabled();
}/**
* Base class from io.quarkus.builder.item package that allows multiple
* instances of the same build item type to be produced.
*/
abstract class MultiBuildItem {
// Inherited from quarkus-core-deployment
}import io.quarkus.smallrye.health.deployment.spi.HealthBuildItem;
// Register an enabled health check
HealthBuildItem activeCheck = new HealthBuildItem(
"com.example.DatabaseHealthCheck",
true
);
// Register a disabled health check
HealthBuildItem inactiveCheck = new HealthBuildItem(
"com.example.CacheHealthCheck",
false
);import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.smallrye.health.deployment.spi.HealthBuildItem;
@BuildStep
HealthBuildItem registerCustomHealthCheck() {
return new HealthBuildItem(
"com.myextension.CustomHealthCheck",
true
);
}