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 2e06d34  CAMEL-16757: Update example
2e06d34 is described below

commit 2e06d3472def6ed14f3341be974ff34bc353d992
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Mon Aug 2 13:30:19 2021 +0200

    CAMEL-16757: Update example
---
 examples/routes-configuration/README.adoc                          | 7 ++++++-
 .../routes-configuration/src/main/resources/application.properties | 5 ++---
 .../myerror/{GlobalErrorHandler.java => JavaErrorHandler.java}     | 4 ++--
 .../src/main/resources/myerror/{global-error.xml => xml-error.xml} | 2 +-
 .../main/resources/myerror/{global-error.yaml => yaml-error.yaml}  | 1 +
 .../myroutes/{MyRouteBuilder.java => MyJavaRouteBuilder.java}      | 6 ++++--
 .../main/resources/myroutes/{cheese-route.xml => my-xml-route.xml} | 3 ++-
 .../src/main/resources/myroutes/my-yaml-route.yaml                 | 2 ++
 8 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/examples/routes-configuration/README.adoc 
b/examples/routes-configuration/README.adoc
index 8e7768c..781fa1e 100644
--- a/examples/routes-configuration/README.adoc
+++ b/examples/routes-configuration/README.adoc
@@ -3,9 +3,14 @@
 This example shows how Camel is capable of loading routes during startup using 
the new route loader system.
 The route loader has support for loading routes in XML, Java and YAML (other 
languages to be added).
 
-In this example the focus is on how you can use global _routes configuration_ 
with the DSL to seperate
+In this example the focus is on how you can use global _routes configuration_ 
with the DSL to separate
 error handling (and other cross routes functionality) from all your routes.
 
+This example has one route in Java, XML and YAML. Each of those routes refer 
to a
+specific route configuration, which is also _coded_ in the same language as 
the route.
+But this is not required, you can use Java to code your route configurations 
for
+advanced error handling, and then _code_ your routes in other languages such 
as XML or YAML.
+
 
 === How to run
 
diff --git 
a/examples/routes-configuration/src/main/resources/application.properties 
b/examples/routes-configuration/src/main/resources/application.properties
index 4f788bb..e328c2e 100644
--- a/examples/routes-configuration/src/main/resources/application.properties
+++ b/examples/routes-configuration/src/main/resources/application.properties
@@ -22,7 +22,6 @@ camel.main.name = MyRoutesConfiguration
 # dump routes as XML (routes are coded in different DSLs but can be dumped as 
XML)
 camel.main.dump-routes = true
 
-# which directory(s) to scan for routes which can be xml, yaml or java files
-# we can control which error handler to use by changing the filter pattern 
(*.xml, *.yaml or *.java)
-camel.main.routes-include-pattern=classpath:myroutes/*,classpath:myerror/*.yaml
+# which directory(s) to scan for routes/route-configurations which can be xml, 
yaml or java files
+camel.main.routes-include-pattern=classpath:myroutes/*,classpath:myerror/*
 
diff --git 
a/examples/routes-configuration/src/main/resources/myerror/GlobalErrorHandler.java
 
b/examples/routes-configuration/src/main/resources/myerror/JavaErrorHandler.java
similarity index 90%
rename from 
examples/routes-configuration/src/main/resources/myerror/GlobalErrorHandler.java
rename to 
examples/routes-configuration/src/main/resources/myerror/JavaErrorHandler.java
index 309555a..86db575 100644
--- 
a/examples/routes-configuration/src/main/resources/myerror/GlobalErrorHandler.java
+++ 
b/examples/routes-configuration/src/main/resources/myerror/JavaErrorHandler.java
@@ -16,11 +16,11 @@
  */
 import org.apache.camel.builder.RouteConfigurationBuilder;
 
-public class GlobalErrorHandler extends RouteConfigurationBuilder {
+public class JavaErrorHandler extends RouteConfigurationBuilder {
 
     @Override
     public void configuration() throws Exception {
-        routeConfiguration()
+        routeConfiguration("javaError")
             .onException(Exception.class).handled(true)
             .log("Java WARN: ${exception.message}");
     }
diff --git 
a/examples/routes-configuration/src/main/resources/myerror/global-error.xml 
b/examples/routes-configuration/src/main/resources/myerror/xml-error.xml
similarity index 96%
rename from 
examples/routes-configuration/src/main/resources/myerror/global-error.xml
rename to examples/routes-configuration/src/main/resources/myerror/xml-error.xml
index dba8481..8184b2b 100644
--- a/examples/routes-configuration/src/main/resources/myerror/global-error.xml
+++ b/examples/routes-configuration/src/main/resources/myerror/xml-error.xml
@@ -18,7 +18,7 @@
 
 -->
 
-<routeConfiguration>
+<routeConfiguration id="xmlError">
     <onException>
         <exception>java.lang.Exception</exception>
         <handled><constant>true</constant></handled>
diff --git 
a/examples/routes-configuration/src/main/resources/myerror/global-error.yaml 
b/examples/routes-configuration/src/main/resources/myerror/yaml-error.yaml
similarity index 98%
rename from 
examples/routes-configuration/src/main/resources/myerror/global-error.yaml
rename to 
examples/routes-configuration/src/main/resources/myerror/yaml-error.yaml
index 67f9c63..44c0824 100644
--- a/examples/routes-configuration/src/main/resources/myerror/global-error.yaml
+++ b/examples/routes-configuration/src/main/resources/myerror/yaml-error.yaml
@@ -16,6 +16,7 @@
 ## ---------------------------------------------------------------------------
 
 - route-configuration:
+    - id: "yamlError"
     - on-exception:
         handled:
           constant: "true"
diff --git 
a/examples/routes-configuration/src/main/resources/myroutes/MyRouteBuilder.java 
b/examples/routes-configuration/src/main/resources/myroutes/MyJavaRouteBuilder.java
similarity index 83%
rename from 
examples/routes-configuration/src/main/resources/myroutes/MyRouteBuilder.java
rename to 
examples/routes-configuration/src/main/resources/myroutes/MyJavaRouteBuilder.java
index b4aef0e..220f548 100644
--- 
a/examples/routes-configuration/src/main/resources/myroutes/MyRouteBuilder.java
+++ 
b/examples/routes-configuration/src/main/resources/myroutes/MyJavaRouteBuilder.java
@@ -18,12 +18,14 @@ import java.util.Random;
 
 import org.apache.camel.builder.RouteBuilder;
 
-public class MyRouteBuilder extends RouteBuilder {
+public class MyJavaRouteBuilder extends RouteBuilder {
 
     @Override
     public void configure() throws Exception {
         from("timer:java?period=2s")
-            .setBody(method(MyRouteBuilder.class, "randomNumber"))
+            // refer to the route configuration by the id to use for this route
+            .routeConfiguration("javaError")
+            .setBody(method(MyJavaRouteBuilder.class, "randomNumber"))
             .log("Random number ${body}")
             .filter(simple("${body} < 30"))
                 .throwException(new IllegalArgumentException("The number is 
too low"));
diff --git 
a/examples/routes-configuration/src/main/resources/myroutes/cheese-route.xml 
b/examples/routes-configuration/src/main/resources/myroutes/my-xml-route.xml
similarity index 91%
rename from 
examples/routes-configuration/src/main/resources/myroutes/cheese-route.xml
rename to 
examples/routes-configuration/src/main/resources/myroutes/my-xml-route.xml
index a21f516..f59a027 100644
--- a/examples/routes-configuration/src/main/resources/myroutes/cheese-route.xml
+++ b/examples/routes-configuration/src/main/resources/myroutes/my-xml-route.xml
@@ -23,7 +23,8 @@
     you can use <routes> as root tag, such as 
<routes><route>...</route><route>...</route></routes>
 -->
 
-<route>
+<!-- refer to the route configuration by the id to use for this route -->
+<route routeConfiguration="xmlError">
     <from uri="timer:xml?period=5s"/>
     <log message="I am XML"/>
     <throwException exceptionType="java.lang.Exception" message="Some kind of 
XML error"/>
diff --git 
a/examples/routes-configuration/src/main/resources/myroutes/my-yaml-route.yaml 
b/examples/routes-configuration/src/main/resources/myroutes/my-yaml-route.yaml
index 0d71afb..6876dac 100644
--- 
a/examples/routes-configuration/src/main/resources/myroutes/my-yaml-route.yaml
+++ 
b/examples/routes-configuration/src/main/resources/myroutes/my-yaml-route.yaml
@@ -16,6 +16,8 @@
 ## ---------------------------------------------------------------------------
 
 - route:
+    # refer to the route configuration by the id to use for this route
+    route-configuration: "yamlError"
     from: "timer:yaml?period=3s"
     steps:
       - set-body:

Reply via email to