Repository: tomee Updated Branches: refs/heads/master 85d7dbb63 -> f1f49d792
This was in .md format but with .adoc extension. So I did the work to convert it. Project: http://git-wip-us.apache.org/repos/asf/tomee/repo Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/fff20762 Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/fff20762 Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/fff20762 Branch: refs/heads/master Commit: fff2076229c5d77850a333b63db2c04dc24dc1b9 Parents: 2446ae8 Author: ivanjunckes <ijunc...@tomitribe.com> Authored: Fri Dec 28 12:24:22 2018 -0200 Committer: Roberto Cortez <radcor...@yahoo.com> Committed: Fri Dec 28 17:18:19 2018 +0000 ---------------------------------------------------------------------- examples/mp-custom-healthcheck/README.adoc | 99 +++++++++++++++---------- 1 file changed, 59 insertions(+), 40 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tomee/blob/fff20762/examples/mp-custom-healthcheck/README.adoc ---------------------------------------------------------------------- diff --git a/examples/mp-custom-healthcheck/README.adoc b/examples/mp-custom-healthcheck/README.adoc index f3e2e01..076661d 100644 --- a/examples/mp-custom-healthcheck/README.adoc +++ b/examples/mp-custom-healthcheck/README.adoc @@ -1,7 +1,13 @@ -# MicroProfile Custom Health Check += MicroProfile Custom Health Check +:index-group: MicroProfile +:jbake-type: page +:jbake-status: published + This is an example of how to use MicroProfile Custom Health Check in TomEE. -#### Health Feature +[discrete] +==== Health Feature + Health checks are used to probe the state of services and resources that an application might depend on or even to expose its state, e.g. in a cluster environment, where an unhealthy node needs to be discarded (terminated, shutdown) and eventually replaced by another healthy instance. @@ -9,18 +15,20 @@ replaced by another healthy instance. By default, https://github.com/eclipse/microprofile-health[microprofile-health-api] provides a basic output of a node by simply hitting the endpoint http://host:port/health. -```json +[source,json] +---- {"checks":[],"outcome":"UP","status":"UP"} -``` +---- -To provide a customized output, Letâs say we have an application that uses a Weather API, and if the service becomes +To provide a customized output, Let's say we have an application that uses a Weather API, and if the service becomes unavailable, we should report the service as DOWN. To begin with a customized output, is needed to implement the interface https://github.com/eclipse/microprofile-health/blob/master/api/src/main/java/org/eclipse/microprofile/health/HealthCheck.java[HealthCheck], make the class a managed bean by annotating it with `@ApplicationScoped` plus with `@Health` annotation to active the custom check. See more here https://github.com/apache/geronimo-health/blob/master/geronimo-health/src/main/java/org/apache/geronimo/microprofile/impl/health/cdi/GeronimoHealthExtension.java[GeronimoHealthExtension.java] -```java +[source,java] +---- @Health @ApplicationScoped public class WeatherServiceHealthCheck implements HealthCheck { @@ -41,34 +49,37 @@ public class WeatherServiceHealthCheck implements HealthCheck { } } } -``` +---- + In the example above, the health probe name is https://openweathermap.org/appid[OpenWeatherMap] (_illustrative only_) which provides a subscription plan to access its services and if the limit of calls is exceeded the API becomes unavailable until it's renewed. -### Examples +[discrete] +=== Examples -##### Running the application - -``` +.Running the application +---- mvn clean install tomee:run -``` +---- -#### Example 1 +[discrete] +==== Example 1 When hitting /health endpoint, OpenWeatherMap tell us that our remaining calls are running out and we should take an action before it gets unavailable. -``` +---- curl http://localhost:8080/mp-custom-healthcheck/health -``` +---- -```json +[source,json] +---- { "checks":[ { "data":{ "weatherServiceApiVersion":"2.5", - "weatherServiceMessage":"Your account will become unavailable soon due to limitation of your + "weatherServiceMessage":"Your account will become unavailable soon due to limitation of your subscription type. Remaining API calls are 1", "weatherServiceApiUrl":"http://api.openweathermap.org/data/2.5/" }, @@ -79,36 +90,40 @@ curl http://localhost:8080/mp-custom-healthcheck/health "outcome":"UP", "status":"UP" } -``` +---- -#### Example 2 +[discrete] +==== Example 2 Weather API still working fine. -``` +---- curl http://localhost:8080/mp-custom-healthcheck/weather/day/status -``` +---- -```text +[source,text] +---- Hi, today is a sunny day! -``` +---- -#### Example 3 +[discrete] +==== Example 3 When hitting one more time /health endpoint, OpenWeatherMap tell us that our account is temporary blocked and this service is being reported as DOWN. -``` +---- curl http://localhost:8080/mp-custom-healthcheck/health -``` +---- -```json +[source,json] +---- { "checks":[ { "data":{ - "weatherServiceErrorMessage":"Your account is temporary blocked due to exceeding of - requests limitation of your subscription type. Please choose the proper subscription + "weatherServiceErrorMessage":"Your account is temporary blocked due to exceeding of + requests limitation of your subscription type. Please choose the proper subscription http://openweathermap.org/price" }, "name":"weatherservice", @@ -118,29 +133,33 @@ curl http://localhost:8080/mp-custom-healthcheck/health "outcome":"DOWN", "status":"DOWN" } -``` +---- -#### Example 4 +[discrete] +==== Example 4 Weather API has stopped. -``` +---- curl http://localhost:8080/mp-custom-healthcheck/weather/day/status -``` +---- -```text +[source,text] +---- Weather Service is unavailable at moment, retry later. -``` +---- -##### Running the tests +[discrete] +===== Running the tests You can also try it out using the link:src/test/java/org/superbiz/rest/WeatherServiceTest.java[WeatherServiceTest.java] available in the project. - mvn clean test +---- +mvn clean test +---- -``` +---- [INFO] Results: [INFO] [INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: -``` - +----