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/11/18 09:59:58 UTC

[camel-examples] 01/05: CAMEL-16656: camel-core - ResourceReloader SPI - Allow to reload on changes

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

commit 7c13a5d5b270385b05df8ecd30e1649f085b4149
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Nov 18 08:57:38 2021 +0100

    CAMEL-16656: camel-core - ResourceReloader SPI - Allow to reload on changes
---
 examples/main-xml/README.adoc                      | 11 ++++---
 examples/main-xml/src/main/data/foo.properties     | 18 ----------
 .../org/apache/camel/example/MyApplication.java    |  4 +++
 .../org/apache/camel/example/MyRouteBuilder.java   | 31 ------------------
 .../src/main/resources/application.properties      | 38 +++++-----------------
 .../src/main/resources/routes/my-route.xml         |  2 +-
 6 files changed, 20 insertions(+), 84 deletions(-)

diff --git a/examples/main-xml/README.adoc b/examples/main-xml/README.adoc
index 4db6d9b..b7ca179 100644
--- a/examples/main-xml/README.adoc
+++ b/examples/main-xml/README.adoc
@@ -1,11 +1,14 @@
 == Camel Example Main XML
 
 This example shows how to run Camel standalone (XML routes) via the built-in Main class.
-The example also demonstrates how you can configure the Camel application
-via Camel built-in dependency-injection that supports binding via the
-`@BindToRegistry`, `@BeanInject` and `@PropertyInject` annotations.
 
-Also notice how you can configure Camel in the `application.properties` file.
+The route is located in `src/main/resources/routes` as an XML file.
+
+This example has been enabled with live reload, so while the Camel
+application is running, then you can edit the route in the XML file,
+and when saved Camel will auto update the route(s).
+
+The application is configured in the `application.properties` file.
 
 === How to run
 
diff --git a/examples/main-xml/src/main/data/foo.properties b/examples/main-xml/src/main/data/foo.properties
deleted file mode 100644
index b43e6bc..0000000
--- a/examples/main-xml/src/main/data/foo.properties
+++ /dev/null
@@ -1,18 +0,0 @@
-## ---------------------------------------------------------------------------
-## 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.
-## ---------------------------------------------------------------------------
-
-bye = Bye
\ No newline at end of file
diff --git a/examples/main-xml/src/main/java/org/apache/camel/example/MyApplication.java b/examples/main-xml/src/main/java/org/apache/camel/example/MyApplication.java
index cb12fc8..0476b5f 100644
--- a/examples/main-xml/src/main/java/org/apache/camel/example/MyApplication.java
+++ b/examples/main-xml/src/main/java/org/apache/camel/example/MyApplication.java
@@ -34,6 +34,10 @@ public final class MyApplication {
         main.configure().addConfigurationClass(MyConfiguration.class);
         // and add all the XML routes
         main.configure().withRoutesIncludePattern("routes/*.xml");
+        // turn on reloading routes on code-changes
+        main.configure().withRoutesReloadEnabled(true);
+        main.configure().withRoutesReloadDirectory("src/main/resources");
+        main.configure().withRoutesReloadPattern("routes/*.xml");
 
         // now keep the application running until the JVM is terminated (ctrl + c or sigterm)
         main.run(args);
diff --git a/examples/main-xml/src/main/java/org/apache/camel/example/MyRouteBuilder.java b/examples/main-xml/src/main/java/org/apache/camel/example/MyRouteBuilder.java
deleted file mode 100644
index c2a1983..0000000
--- a/examples/main-xml/src/main/java/org/apache/camel/example/MyRouteBuilder.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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.builder.RouteBuilder;
-
-public class MyRouteBuilder extends RouteBuilder {
-
-    @Override
-    public void configure() throws Exception {
-        from("quartz:foo?cron={{myCron}}")
-            .bean("myBean", "hello")
-            .log("${body}")
-            .bean("myBean", "bye")
-            .log("${body}");
-    }
-}
diff --git a/examples/main-xml/src/main/resources/application.properties b/examples/main-xml/src/main/resources/application.properties
index 242773d..74c10c0 100644
--- a/examples/main-xml/src/main/resources/application.properties
+++ b/examples/main-xml/src/main/resources/application.properties
@@ -17,45 +17,23 @@
 
 # to configure camel main
 # here you can configure options on camel main (see MainConfigurationProperties class)
-camel.main.name = MyCoolCamel
-camel.main.jmx-enabled = false
+camel.main.name = MyXmlCamel
 
-# extended runtime statistics about bean introspection usage (java reflection)
-# camel.main.bean-introspection-extended-statistics=true
-# camel.main.bean-introspection-logging-level=INFO
-
-# enable tracing
-# camel.main.tracing = true
-# configure tracing what to include from the exchange
-#camel.context.tracer.exchange-formatter.show-exchange-id = false
-#camel.context.tracer.exchange-formatter.show-headers = true
-#camel.context.tracer.exchange-formatter.show-body-type = false
-
-# you can also configure camel context directly
-# camel.context.shutdown-strategy.shutdown-now-on-timeout = false
-
-# load additional property placeholders from this folder
-camel.main.file-configurations=src/main/data/*.properties
+# turn on route reloading on file changes
+camel.main.routes-reload-enabled = true
+# the base directory to watch
+camel.main.routes-reload-directory = src/main/resources
+# pattern(s) for files to watch
+camel.main.routes-reload-pattern = routes/*.xml
 
 # 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
 
-# to configure Hystrix EIP (global and you need to add camel-hystrix to the classpath)
-### camel.hystrix.group-key=myGroup
-### camel.hystrix.execution-timeout-in-milliseconds=5000
-
-# to configure Rest DSL (global and you need to add camel-undertow to the classpath)
-### camel.rest.component=undertow
-### camel.rest.port=8080
-### camel.rest.component-properties[host-options.buffer-size]=8192
-
-# you can configure whether OS environment should override (=2 which is default) or as fallback (=1)
-### camel.component.properties.environment-variable-mode=1
-
 # properties used in the route
 myCron = 0/2 * * * * ?
 
 # application properties
 hi = Hello
+bye = Bye
 
diff --git a/examples/main-xml/src/main/resources/routes/my-route.xml b/examples/main-xml/src/main/resources/routes/my-route.xml
index 43d71c4..0d9c1c2 100644
--- a/examples/main-xml/src/main/resources/routes/my-route.xml
+++ b/examples/main-xml/src/main/resources/routes/my-route.xml
@@ -18,7 +18,7 @@
 
 -->
 <routes id="camel" xmlns="http://camel.apache.org/schema/spring">
-    <route>
+    <route id="foo">
         <from uri="quartz:foo?cron={{myCron}}"/>
         <bean ref="myBean" method="hello"/>
         <log message="${body}"/>