This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-examples.git


The following commit(s) were added to refs/heads/master by this push:
     new 89a3e65  camel-example-mian-health-check example
89a3e65 is described below

commit 89a3e65817129e080cabf37628af65758efa3b3a
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Fri May 29 21:00:18 2020 +0200

    camel-example-mian-health-check example
---
 examples/camel-example-main-health/pom.xml         | 105 +++++++++++++++++++++
 examples/camel-example-main-health/readme.adoc     |  29 ++++++
 .../apache/camel/example/MonkeyHealthCheck.java    |  54 +++++++++++
 .../org/apache/camel/example/MyApplication.java    |  41 ++++++++
 .../org/apache/camel/example/MyConfiguration.java  |  31 ++++++
 .../org/apache/camel/example/MyRouteBuilder.java   |  34 +++++++
 .../src/main/resources/application.properties      |  35 +++++++
 .../src/main/resources/logback.xml                 |  30 ++++++
 examples/pom.xml                                   |   1 +
 9 files changed, 360 insertions(+)

diff --git a/examples/camel-example-main-health/pom.xml 
b/examples/camel-example-main-health/pom.xml
new file mode 100644
index 0000000..e41e0d6
--- /dev/null
+++ b/examples/camel-example-main-health/pom.xml
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.camel.example</groupId>
+        <artifactId>examples</artifactId>
+        <version>3.4.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>camel-example-main-health</artifactId>
+    <packaging>jar</packaging>
+    <name>Camel :: Example :: Main Health</name>
+    <description>An example for showing standalone Camel with Health 
Checks</description>
+
+    <properties>
+        <category>Beginner</category>
+    </properties>
+
+    <dependencyManagement>
+        <dependencies>
+            <!-- Add Camel BOM -->
+            <dependency>
+                <groupId>org.apache.camel</groupId>
+                <artifactId>camel-bom</artifactId>
+                <version>${camel.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-main</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-management</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-quartz</artifactId>
+        </dependency>
+
+        <!-- logging -->
+        <dependency>
+            <groupId>org.apache.logging.log4j</groupId>
+            <artifactId>log4j-api</artifactId>
+            <version>${log4j2-version}</version>
+            <scope>runtime</scope>
+        </dependency>
+        <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-core</artifactId>
+            <version>${logback-version}</version>
+        </dependency>
+        <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-classic</artifactId>
+            <version>${logback-version}</version>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.camel</groupId>
+                <artifactId>camel-maven-plugin</artifactId>
+                <version>${camel.version}</version>
+                <configuration>
+                    <logClasspath>false</logClasspath>
+                    
<mainClass>org.apache.camel.example.MyApplication</mainClass>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
diff --git a/examples/camel-example-main-health/readme.adoc 
b/examples/camel-example-main-health/readme.adoc
new file mode 100644
index 0000000..575ecd5
--- /dev/null
+++ b/examples/camel-example-main-health/readme.adoc
@@ -0,0 +1,29 @@
+== Camel Example Main Health
+
+This example shows how to use Camel health-check in standalone mode.
+The example shows how you can build custom health-checks and have
+them automatic discovered by Camel and used as parts of its health-check 
system.
+
+=== How to run
+
+You can run this example using
+
+[source,shell]
+----
+mvn camel:run
+----
+
+=== JMX Management
+
+You can from JMX see the health-check status in the Camel tree under health and
+find the DefaultHealthCheck MBean.
+
+=== Help and contributions
+
+If you hit any problem using Camel or have some feedback, then please
+https://camel.apache.org/support.html[let us know].
+
+We also love contributors, so
+https://camel.apache.org/contributing.html[get involved] :-)
+
+The Camel riders!
diff --git 
a/examples/camel-example-main-health/src/main/java/org/apache/camel/example/MonkeyHealthCheck.java
 
b/examples/camel-example-main-health/src/main/java/org/apache/camel/example/MonkeyHealthCheck.java
new file mode 100644
index 0000000..f66ca76
--- /dev/null
+++ 
b/examples/camel-example-main-health/src/main/java/org/apache/camel/example/MonkeyHealthCheck.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.example;
+
+import java.util.Map;
+
+import org.apache.camel.health.HealthCheckResultBuilder;
+import org.apache.camel.impl.health.AbstractHealthCheck;
+
+/**
+ * A chaos monkey health check that reports UP or DOWN in a chaotic way.
+ *
+ * This is a custom implementation of a Camel {@link 
org.apache.camel.health.HealthCheck}
+ * which is automatic discovered if bound in the {@link 
org.apache.camel.spi.Registry} and
+ * used as part of Camel's health-check system.
+ */
+public class MonkeyHealthCheck extends AbstractHealthCheck {
+
+    private boolean up = true;
+
+    protected MonkeyHealthCheck() {
+        super("custom", "monkey");
+    }
+
+    @Override
+    protected void doCall(HealthCheckResultBuilder builder, Map<String, 
Object> options) {
+        builder.detail("monkey", "The chaos monkey was here");
+         if (up) {
+             builder.up();
+         } else {
+             builder.down();
+         }
+    }
+
+    public String chaos() {
+        up = !up;
+        return up ? "All is okay" : "Chaos monkey was here";
+    }
+
+}
diff --git 
a/examples/camel-example-main-health/src/main/java/org/apache/camel/example/MyApplication.java
 
b/examples/camel-example-main-health/src/main/java/org/apache/camel/example/MyApplication.java
new file mode 100644
index 0000000..b6dce99
--- /dev/null
+++ 
b/examples/camel-example-main-health/src/main/java/org/apache/camel/example/MyApplication.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.example;
+
+import org.apache.camel.main.Main;
+
+/**
+ * Main class that boot the Camel application
+ */
+public final class MyApplication {
+
+    private MyApplication() {
+    }
+
+    public static void main(String[] args) throws Exception {
+        // use Camels Main class
+        Main main = new Main();
+        // lets use a configuration class (you can specify multiple classes)
+        // (properties are automatic loaded from application.properties)
+        main.configure().addConfigurationClass(MyConfiguration.class);
+        // and add the routes (you can specify multiple classes)
+        main.configure().addRoutesBuilder(MyRouteBuilder.class);
+        // now keep the application running until the JVM is terminated (ctrl 
+ c or sigterm)
+        main.run(args);
+    }
+
+}
diff --git 
a/examples/camel-example-main-health/src/main/java/org/apache/camel/example/MyConfiguration.java
 
b/examples/camel-example-main-health/src/main/java/org/apache/camel/example/MyConfiguration.java
new file mode 100644
index 0000000..6648f8e
--- /dev/null
+++ 
b/examples/camel-example-main-health/src/main/java/org/apache/camel/example/MyConfiguration.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.example;
+
+import org.apache.camel.BindToRegistry;
+
+/**
+ * Class to configure the Camel application.
+ */
+public class MyConfiguration {
+
+    @BindToRegistry
+    public MonkeyHealthCheck monkey() {
+        return new MonkeyHealthCheck();
+    }
+
+}
diff --git 
a/examples/camel-example-main-health/src/main/java/org/apache/camel/example/MyRouteBuilder.java
 
b/examples/camel-example-main-health/src/main/java/org/apache/camel/example/MyRouteBuilder.java
new file mode 100644
index 0000000..e42df41
--- /dev/null
+++ 
b/examples/camel-example-main-health/src/main/java/org/apache/camel/example/MyRouteBuilder.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.example;
+
+import org.apache.camel.BeanInject;
+import org.apache.camel.builder.RouteBuilder;
+
+public class MyRouteBuilder extends RouteBuilder {
+
+    // we can inject the bean via this annotation
+    @BeanInject("monkey")
+    MonkeyHealthCheck monkey;
+
+    @Override
+    public void configure() throws Exception {
+        from("quartz:foo?cron={{myCron}}").routeId("foo")
+            .bean(monkey, "chaos")
+            .log("${body}");
+    }
+}
diff --git 
a/examples/camel-example-main-health/src/main/resources/application.properties 
b/examples/camel-example-main-health/src/main/resources/application.properties
new file mode 100644
index 0000000..67fc988
--- /dev/null
+++ 
b/examples/camel-example-main-health/src/main/resources/application.properties
@@ -0,0 +1,35 @@
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements.  See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License.  You may obtain a copy of the License at
+##
+##      http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+
+# to configure camel main
+# here you can configure options on camel main (see 
MainConfigurationProperties class)
+camel.main.name = MyHealthyCamel
+
+# enable JMX which allows to also control health check
+camel.main.jmx-enabled = true
+
+# enable health check (is automatic enabled if discovered on classpath)
+camel.main.route-controller-supervise-enabled = true
+camel.main.health-check-enabled = true
+camel.main.health-check-routes-enabled = true
+
+# to configure the camel quartz component
+# here we can configure the options on the component level (and we can use 
dash-naming-style)
+camel.component.quartz.start-delayed-seconds = 3
+
+# properties used in the route
+myCron = 0/10 * * * * ?
diff --git a/examples/camel-example-main-health/src/main/resources/logback.xml 
b/examples/camel-example-main-health/src/main/resources/logback.xml
new file mode 100644
index 0000000..a798d0b
--- /dev/null
+++ b/examples/camel-example-main-health/src/main/resources/logback.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+
+-->
+<configuration>
+    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+        <encoder>
+            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - 
%msg%n</pattern>
+        </encoder>
+    </appender>
+
+    <root level="INFO">
+        <appender-ref ref="STDOUT" />
+    </root>
+</configuration>
diff --git a/examples/pom.xml b/examples/pom.xml
index 55ed2d2..e2eb016 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -129,6 +129,7 @@
         <module>camel-example-main</module>
         <module>camel-example-main-artemis</module>
         <module>camel-example-main-endpointdsl</module>
+        <module>camel-example-main-health</module>
         <module>camel-example-main-tiny</module>
         <module>camel-example-main-xml</module>
         <module>camel-example-management</module>

Reply via email to