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 2020/07/17 08:13:24 UTC

[camel-examples] branch master updated: CAMEL-15270: camel-main can configure route templates from properties files.

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 8385003  CAMEL-15270: camel-main can configure route templates from properties files.
8385003 is described below

commit 838500392cc5fe9333ba9ed38fc78f360ef74152
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Jul 17 10:11:53 2020 +0200

    CAMEL-15270: camel-main can configure route templates from properties files.
---
 examples/camel-example-routetemplate/readme.adoc              |  6 +++++-
 .../src/main/java/org/apache/camel/example/MyApplication.java | 11 ++++++++++-
 .../src/main/resources/application.properties                 |  9 +++++++++
 3 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/examples/camel-example-routetemplate/readme.adoc b/examples/camel-example-routetemplate/readme.adoc
index 3cb8476..9d14ad5 100644
--- a/examples/camel-example-routetemplate/readme.adoc
+++ b/examples/camel-example-routetemplate/readme.adoc
@@ -4,7 +4,11 @@ This examples shows how to use Route Templates (parameterized routes) to specify
 which can be used for creating and adding new routes via parameters.
 
 The route template is defined via Java or XML DSL (RouteBuilder) in the `MyRouteTemplates.java` source file.
-The `MyConfiguration.java` is used to create two routes from the template using different set of parameters.
+
+The `application.properties` is used to create two routes from the template using different set of parameters.
+
+An alternative to create routes is from Java which is done in the `MyConfiguration.java` class.
+See the `MyApplication.java` where you can change the source to use java instead of property file for the template parameters.
 
 The example runs standalone via Camel Main in the `MyApplication.java` source file.
 
diff --git a/examples/camel-example-routetemplate/src/main/java/org/apache/camel/example/MyApplication.java b/examples/camel-example-routetemplate/src/main/java/org/apache/camel/example/MyApplication.java
index 955b0a2..6b9e4f4 100644
--- a/examples/camel-example-routetemplate/src/main/java/org/apache/camel/example/MyApplication.java
+++ b/examples/camel-example-routetemplate/src/main/java/org/apache/camel/example/MyApplication.java
@@ -32,7 +32,16 @@ public final class MyApplication {
         // and add route templates via routes builder
         main.configure().addRoutesBuilder(MyRouteTemplates.class);
         // add configuration class which setup the routes from the route templates
-        main.configure().addConfigurationClass(MyConfiguration.class);
+
+        // to configure route templates we can use java code as below from a configuration class,
+        // gives more power as its java code.
+        // or we can configure as well from application.properties,
+        // less power as its key value pair properties
+        // and you can also use both java and properties together
+
+        // in this example we use properties by default and have disabled java
+        // main.configure().addConfigurationClass(MyConfiguration.class);
+
         // now keep the application running until the JVM is terminated (ctrl + c or sigterm)
         main.run(args);
     }
diff --git a/examples/camel-example-routetemplate/src/main/resources/application.properties b/examples/camel-example-routetemplate/src/main/resources/application.properties
index df19913..52fc3fd 100644
--- a/examples/camel-example-routetemplate/src/main/resources/application.properties
+++ b/examples/camel-example-routetemplate/src/main/resources/application.properties
@@ -19,6 +19,15 @@
 # here you can configure options on camel main (see MainConfigurationProperties class)
 camel.main.name = MyCoolCamel
 
+# create routes from the route template
+# this can also be done in Java code, see MyConfiguration.java
+camel.route-template[0].template-id = myTemplate
+camel.route-template[0].name = one
+camel.route-template[0].greeting = Hello
+camel.route-template[1].template-id = myTemplate
+camel.route-template[1].name = two
+camel.route-template[1].greeting = Bonjour
+camel.route-template[1].my-period = 5s
 
 # application properties
 hi = Hello