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-kamelets-examples.git


The following commit(s) were added to refs/heads/main by this push:
     new a0bdf8b  A chaos monkey example
a0bdf8b is described below

commit a0bdf8bd3e8383c857bb49f46942e21b58cf6d48
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Jul 1 16:10:53 2022 +0200

    A chaos monkey example
---
 jbang/chaos-monkey/ChaosMonkey.java | 30 +++++++++++++++
 jbang/chaos-monkey/README.adoc      | 77 +++++++++++++++++++++++++++++++++++++
 jbang/chaos-monkey/route.yaml       | 10 +++++
 3 files changed, 117 insertions(+)

diff --git a/jbang/chaos-monkey/ChaosMonkey.java 
b/jbang/chaos-monkey/ChaosMonkey.java
new file mode 100644
index 0000000..9651b7f
--- /dev/null
+++ b/jbang/chaos-monkey/ChaosMonkey.java
@@ -0,0 +1,30 @@
[email protected]("chaosMonkeyCheck")
+public class ChaosMonkey extends 
org.apache.camel.impl.health.AbstractHealthCheck {
+
+    private int num;
+
+    public ChaosMonkey() {
+        super("acme", "chaos");
+        System.out.println("Installing Chaos Monkey");
+    }
+
+    public String status(String body) {
+        num = new java.util.Random().nextInt(10);
+         if (num < 4) {
+            return "Chaos Moneky is here";
+        } else {
+            return body;    
+        }
+    }
+
+    @Override
+    public void doCall(org.apache.camel.health.HealthCheckResultBuilder 
builder, java.util.Map<String, Object> options) {
+        if (num < 4) {
+            builder.detail("number-number", num).down();
+        } else {
+            builder.detail("chaos-number", num).up();    
+        }
+    }
+
+
+}
\ No newline at end of file
diff --git a/jbang/chaos-monkey/README.adoc b/jbang/chaos-monkey/README.adoc
new file mode 100644
index 0000000..0ae924d
--- /dev/null
+++ b/jbang/chaos-monkey/README.adoc
@@ -0,0 +1,77 @@
+== Chaos Monkey
+
+This example shows a chaos moneky with Camel JBang.
+
+When everything is okay then Camel reports UP in the helath check.
+But the chaos monkey can from time to time cause problems and the health check 
is then DOWN.
+
+
+=== Install JBang
+
+First install JBang according to https://www.jbang.dev
+
+When JBang is installed then you should be able to run from a shell:
+
+[source,sh]
+----
+$ jbang --version
+----
+
+This will output the version of JBang.
+
+To run this example you can either install Camel on JBang via:
+
+[source,sh]
+----
+$ jbang app install camel@apache/camel
+----
+
+Which allows to run CamelJBang with `camel` as shown below.
+
+=== How to run
+
+Then you can run this example using:
+
+[source,sh]
+----
+$ camel run *
+----
+
+Or run with JBang using the longer command line (without installing camel as 
app in JBang):
+
+[source,sh]
+----
+$ jbang camel@apache/camel run *
+----
+
+=== Run directly from github
+
+The example can also be run directly by referring to the github URL as shown:
+
+[source,sh]
+----
+$ jbang camel@apache/camel run 
https://github.com/apache/camel-kamelets-examples/tree/main/jbang/chaos-monkey
+----
+
+=== Helath Check Console
+
+You can enable the health check console via `--health` flag as show:
+
+[source,sh]
+----
+$ camel run * --health
+----
+
+Then you can browse: http://localhost:8080/q/health to introspect the health 
check
+of the running application. When the chaos moneky is causing problems then the 
check is DOWN otherwise its UP.
+
+
+=== Help and contributions
+
+If you hit any problem using Camel or have some feedback, then please
+https://camel.apache.org/community/support/[let us know].
+
+We also love contributors, so
+https://camel.apache.org/community/contributing/[get involved] :-)
+
+The Camel riders!
diff --git a/jbang/chaos-monkey/route.yaml b/jbang/chaos-monkey/route.yaml
new file mode 100644
index 0000000..d3c4512
--- /dev/null
+++ b/jbang/chaos-monkey/route.yaml
@@ -0,0 +1,10 @@
+- route:
+    from:
+      uri: kamelet:timer-source?period=5000&message=hello
+      steps:
+        - to:
+            uri: bean:chaosMonkeyCheck?method=status
+        - to:
+            uri: microprofile-metrics:counter:messages
+        - log:
+            message: ${body}
\ No newline at end of file

Reply via email to