You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2021/10/29 11:17:09 UTC
[camel] 11/16: CAMEL-15133: Adding fine-grained consumer health
check to route checks
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch custom-health
in repository https://gitbox.apache.org/repos/asf/camel.git
commit b11ca32cc8f35cd821a93af92aaa0960144fe241
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Oct 29 07:31:20 2021 +0200
CAMEL-15133: Adding fine-grained consumer health check to route checks
---
.../modules/ROOT/pages/health-check.adoc | 44 +++++++++++++---------
1 file changed, 27 insertions(+), 17 deletions(-)
diff --git a/docs/user-manual/modules/ROOT/pages/health-check.adoc b/docs/user-manual/modules/ROOT/pages/health-check.adoc
index 053f68b..c87976c 100644
--- a/docs/user-manual/modules/ROOT/pages/health-check.adoc
+++ b/docs/user-manual/modules/ROOT/pages/health-check.adoc
@@ -10,13 +10,16 @@ Camel provides support to probe the state of an integration via a pluggable Heal
== Health checks out of the box
-Camel provides three standard health checks out of the box
+Camel provides the following health checks out of the box:
- context - A `HealthCheck` which performs check whether the `CamelContext` is started. This can be used for readiness checks; to know when Camel is fully started and ready to handle traffic.
- routes - A `HealthCheckRegistry` which discovers all the available routes in `CamelContext` and checks whether they are all started.
This can be used for readiness checks; to know when Camel is fully started and ready to handle traffic.
Combining with the supervised `RouteController` this allows to perform readiness check for routes that are under supervising,
- such as troublesome routes that may not startup the first time, and are retried to be started in the background with backoff delays.
+ such as troublesome routes that may not start up the first time, and are retried to be started in the background with backoff delays.
+- consumer (scheduled polling consumer) - A `ScheduledPollConsumerHealthCheck` which automatic integrates with the *routes* health check
+ which enables fine-grained checks for the route input. This means if the consumer is failing to poll new messages
+ then the health check can detect this and report as un-healthy.
- registry - A `HealthCheckRegistry` which discovers all the available custom `HealthCheck` instances in the `Registry`.
== IDs
@@ -26,19 +29,22 @@ With the suffix `-health-check` or `-health-check-repository`. When looking up o
For example `context-health-check` is the ID but can also be used by its shorthand `context`.
+The ID of the `ScheduledPollConsumerHealthCheck` is the route id with `route:` as prefix, eg if the route
+is named foo, then the ID is `route:foo`.
+
== Readiness and Liveness
-A health check is by default useable for both readiness and liveness checks.
+A health check is by default usable for both readiness and liveness checks.
-To specify a custom health check as only useable for liveness checks,
+To specify a custom health check as only usable for liveness checks,
you would need to turn off readiness, by overriding the `isReadiness` method and return `false`.
[source,java]
----
- @Override
- public boolean isReadiness() {
- return false;
- }
+@Override
+public boolean isReadiness() {
+ return false;
+}
----
== Health Check configuration
@@ -49,7 +55,7 @@ The `HealthCheckConfiguration` has the following options:
|====
| Name | Default | Description
| enabled | true | Set if the check associated to this configuration is enabled or not.
-| interval | | Set the check interval in milli seconds.
+| interval | | Set the check interval in milliseconds.
| failureThreshold | | Set the number of failure before reporting the service as un-healthy.
|====
@@ -64,8 +70,8 @@ So in other words after minimum 50 seconds and 5 calls then it can be reported a
Camel supports via `camel-main` to configure health-checks from configuration files. This is possible for runtimes that leverage `camel-main`
such as Camel on Spring Boot, or Camel K.
-Camel will automatic enable `context`, `routes` and `registry` health-checks if `camel-health` is detected on the classpath.
-They are all enabled by default. However you can configure them, for example to turn it off:
+Camel will automatically enable `context`, `routes` and `registry` health-checks if `camel-health` is detected on the classpath.
+They are all enabled by default. However, you can configure them, for example to turn it off:
[source,properties]
----
@@ -84,7 +90,7 @@ camel.health.registryEnabled=false
The `routes` health check supports filtering by route id, or endpoint uri using a pattern style (* as wildcard, and regexp supported).
For example to turn off all routes that are from kafka, you can do:
-NOTE: Notice the syntax is a map `[]` where the key is the route id pattern. Its important to set the `parent`
+NOTE: Notice the syntax is a map `[]` where the key is the route id pattern. It's important to set the `parent`
option to refer to what health-check this configuration applies for such as `routes` or `registry`.
[source,properties]
@@ -94,6 +100,7 @@ camel.health.config[kafka*].enabled=false
----
It's possible to set a default fallback configuration using `[*]` as the route id:
+
[source,properties]
----
camel.health.config[kafka*].parent=routes
@@ -105,7 +112,7 @@ camel.health.config[*].failure-threshold=10
== JMX management
-The health check is managable via JMX (requires `camel-management` JAR on the classpath).
+The health check is manageable via JMX (requires `camel-management` JAR on the classpath).
You can find the `DefaultHealthCheck` MBean under the `health` node in the Camel JMX tree.
This MBean allows at runtime to manage health-checks where you can enable and disable checks based on their IDs.
@@ -115,14 +122,16 @@ The MBean also allows invoking health checks based on IDs (or all of them).
== Invoking health checks
You can invoke the health checks from Java by using the `org.apache.camel.health.HealthCheckHelper` which has APIs
-to easily invoke all the health checks and gather their results, or filter out unwanated checkes, or invoke only
+to easily invoke all the health checks and gather their results, or filter out unwanted checks, or invoke only
the readiness or liveness checks.
The health checks can also be invoked from JMX.
== Writing a custom health check:
-There are a limited number of health checks provided by Camel out of the box, so you may need to write your own check which you can do by implementing the _HealthCheck_ interface or by extending _AbstractHealthCheck_ which provides some useful methods:
+There are a limited number of health checks provided by Camel out of the box,
+so you may need to write your own check which you can do by implementing the _HealthCheck_ interface
+or by extending _AbstractHealthCheck_ which provides some useful methods:
[source,java]
----
@@ -149,9 +158,10 @@ public final class MyHealthCheck extends AbstractHealthCheck {
}
----
-You can now make _MyHealthCheck_ available to Camel by adding an instance to (for example Spring application context) or directly to the Camel xref:registry.adoc[Registry].
+You can now make _MyHealthCheck_ available to Camel by adding an instance to (for example Spring application context)
+or directly to the Camel xref:registry.adoc[Registry].
-TIP: The example `camel-example-main-health` has a custom health check.
+TIP: The example `main-health` has a custom health check.
== Examples