This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-examples.git
The following commit(s) were added to refs/heads/main by this push:
new a193c1b Allow the health check to flip between UP and DOWN (#58)
a193c1b is described below
commit a193c1b043312d37757e0c79b281a50efe583206
Author: Nicolas Filotto <[email protected]>
AuthorDate: Thu Jan 27 07:02:57 2022 +0100
Allow the health check to flip between UP and DOWN (#58)
---
.../main/java/org/apache/camel/example/MonkeyHealthCheck.java | 4 ++--
.../src/main/java/org/apache/camel/example/MyRouteBuilder.java | 10 ++--------
2 files changed, 4 insertions(+), 10 deletions(-)
diff --git
a/examples/main-health/src/main/java/org/apache/camel/example/MonkeyHealthCheck.java
b/examples/main-health/src/main/java/org/apache/camel/example/MonkeyHealthCheck.java
index ba6169e..1c16596 100644
---
a/examples/main-health/src/main/java/org/apache/camel/example/MonkeyHealthCheck.java
+++
b/examples/main-health/src/main/java/org/apache/camel/example/MonkeyHealthCheck.java
@@ -32,7 +32,7 @@ import org.apache.camel.spi.annotations.HealthCheck;
@HealthCheck("monkey-check")
public class MonkeyHealthCheck extends AbstractHealthCheck {
- private boolean up = true;
+ private static boolean up = true;
public MonkeyHealthCheck() {
super("custom", "monkey");
@@ -48,7 +48,7 @@ public class MonkeyHealthCheck extends AbstractHealthCheck {
}
}
- public String chaos() {
+ public static String chaos() {
up = !up;
return up ? "All is okay" : "Chaos monkey was here";
}
diff --git
a/examples/main-health/src/main/java/org/apache/camel/example/MyRouteBuilder.java
b/examples/main-health/src/main/java/org/apache/camel/example/MyRouteBuilder.java
index 6eb457d..5e590a1 100644
---
a/examples/main-health/src/main/java/org/apache/camel/example/MyRouteBuilder.java
+++
b/examples/main-health/src/main/java/org/apache/camel/example/MyRouteBuilder.java
@@ -16,22 +16,16 @@
*/
package org.apache.camel.example;
-import org.apache.camel.ExtendedCamelContext;
import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.health.HealthCheck;
-import org.apache.camel.health.HealthCheckResolver;
public class MyRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
// to trigger the health check to flip between UP and DOWN then lets
call it as a Java bean from
- // a route, and therefore we need to lookup and resolve the
monkey-check
- HealthCheckResolver resolver =
getCamelContext().adapt(ExtendedCamelContext.class).getHealthCheckResolver();
- final HealthCheck monkey = resolver.resolveHealthCheck("monkey");
-
+ // a route
from("timer:foo?period={{myPeriod}}").routeId("timer")
- .bean(monkey, "chaos")
+ .bean(MonkeyHealthCheck.class, "chaos")
.log("${body}");
// this route is invalid and fails during startup