[JAVA] Get in touch with Eclipse MicroProfile Health

Introduction

This time, I would like to try Eclipse MicroProfile Health, which was outlined earlier in Eclipse MicroProfile.

How to get started

This time too, I introduced it earlier in How to get started with Eclipse MicroProfile. We will use MicroProfile Starter.

image.png

Create and download a project with this setting.

The file structure is as follows.

image.png

When you build, start the application and access localhost: 8080, the following Top screen is prepared.

image.png

When you access Health status (with custom status Service HealthCheck), you will see the following:

image.png

It's hard to see if it's left as it is, so open it in Firefox.

image.png

You can respond to the health check results!

Implementation description

ServiceHealthCheck.java


import org.eclipse.microprofile.health.Health;
import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;

import javax.enterprise.context.ApplicationScoped;

//Annotation indicating that a health check is performed, but it is deprecated in the latest version. Things that no longer need to be annotated
@Health
@ApplicationScoped
//By implementing HealthCheck, check items and response contents can be defined.
public class ServiceHealthCheck implements HealthCheck {

    @Override
    public HealthCheckResponse call() {
//Respond that the health check item called Service Health Check is Up
        return HealthCheckResponse.named(ServiceHealthCheck.class.getSimpleName()).up().build();

    }
}

Here, if you look at the Json of the response content earlier,

4 items have been returned. ServiceHealthCheck is implemented above, but the other three are not implemented, so it can be said that they are health check items prepared in advance on the Helidon side.

Check type

In addition to the @Health introduced this time, the following are defined as specifications.

--Define as a Readiness check @Readiness --Check if the application is ready to process the request --Define as a Liveness check @Liveness --Determine if the application is running. This means that if you return Down, you can destroy (quit, shut down) the application.

Summary

This time, the explanation was limited to the minimum configuration, but did you understand how easy it is to start using it? Next time I would like to try another specification

Reference link

--Official document

MicroProfile Health

Recommended Posts

Get in touch with Eclipse MicroProfile Health
MVC in Eclipse.
How to get started with Eclipse Micro Profile
I tried Eclipse MicroProfile OpenAPI with WildFly Swarm
Get along with Java containers in Cloud Run
How to switch Tomcat context.xml with WTP in Eclipse
Where to get lost in specifications with Spark routing
[Java] Get the file path in the folder with List
Until you start development with Spring Boot in eclipse 1
How to use JDD library in Scala with Eclipse
Until you start development with Spring Boot in eclipse 2
About Eclipse MicroProfile Config
To debug in eclipse
Get started with Gradle
Get cookies in Spring
MicroProfile OpenTracing with Helidon
Eclipse MicroProfile JAX-RS implementation
How to get values in real time with TextWatcher (Android)
In Redmine you can get the project with Project.find (<identifier>)