Simplest Possible Microprofile Liveness Check

A health check can be exposed using the org.eclipse.microprofile.health.Health qualifier exposing a HealthCheckResponse:


import javax.enterprise.context.ApplicationScoped;
import org.eclipse.microprofile.health.Health;
import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;    
@Health
@ApplicationScoped
public class LivenessCheck implements HealthCheck {

    @Override
    public HealthCheckResponse call() {
        return HealthCheckResponse.
                named("ping").
                up().
                withData("duke", "lives").
                build();
    }

}

The health check is available from the "root" URL (not the WAR URI):

curl http://localhost:8080/health outputs:

{"outcome":"UP","checks":[{"name":"ping","state":"UP","data":{"duke":"lives"}}]}

The API is included in the microprofile BOM:


 <project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.airhacks</groupId>
<artifactId>microprofile</artifactId>
<version>0.0.1</version>
<packaging>war</packaging>
<dependencies>
   <dependency>
       <groupId>org.eclipse.microprofile</groupId>
       <artifactId>microprofile</artifactId>
       <version>1.2</version>
       <type>pom</type>
       <scope>provided</scope>
   </dependency>
</dependencies>
<build>
   <finalName>microprofile</finalName>
</build>
<properties>
   <maven.compiler.source>1.8</maven.compiler.source>
   <maven.compiler.target>1.8</maven.compiler.target>
   <failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
</project>    

The above example comes with 4.2 kB WAR and runs on stock Payara Server 5. Payara 5 comes with Java EE 8 and microprofile 1.2 support.

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.

Comments:

Unfortunately there are some bugs in the Payara Healthcheck.
https://github.com/payara/Payara/issues/2595
https://github.com/payara/Payara/issues/2641

Posted by Bastian on April 17, 2018 at 03:42 PM CEST #

Hi Bastian, the issues you linked are not bugs but points not yet covered by the MicroProfile Health specification. What those issues report is a missing "readiness" check to report when applications are ready to respond or failed deployment. This should be addressed in the future but it's a problem in any MicroProfile Health implementation, not only in Payara

Posted by Ondro on July 23, 2018 at 11:37 AM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
...the last 150 posts
...the last 10 comments
License