@Readiness and @Liveness annotations on methods using CDI does not work

28 Views Asked by At

I am trying to add Liveness and Readiness probes in my java service. I want to use the CDI method of annotating individual methods rather than having the class annotation and then calling multiple checks in the call() method. However when the service is deployed, these health checks are not detected and executed. I am using microprofile 4.0.1 in the dependencies. Is there anything missing in the below code or is it not supported in this version of microprofile?

import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;
import org.eclipse.microprofile.health.Liveness;
import org.eclipse.microprofile.health.Readiness;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;

@ApplicationScoped
public class HealthProducer {
    
    @Produces
    @Liveness
    HealthCheck live() {
        return () -> HealthCheckResponse.named("live-check").up().build();
    }
    
    @Produces
    @Readiness
    HealthCheck ready() {
        return () -> HealthCheckResponse.named("ready-check").up().build();
    }
}

PS: The regular way of implementing HealthCheck class and overriding the call() method works fine and calls the health check method in the same setup. The CDI method does not work.

0

There are 0 best solutions below