This time, I would like to try Eclipse MicroProfile Health, which was outlined earlier in Eclipse MicroProfile.
This time too, I introduced it earlier in How to get started with Eclipse MicroProfile. We will use MicroProfile Starter.
Create and download a project with this setting.
The file structure is as follows.
When you build, start the application and access localhost: 8080, the following Top screen is prepared.
When you access Health status (with custom status Service HealthCheck), you will see the following:
It's hard to see if it's left as it is, so open it in Firefox.
You can respond to the health check results!
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.
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.
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
--Official document
Recommended Posts