CAMEL-14963: Route Template example.
diff --git a/examples/camel-example-routetemplate/readme.adoc b/examples/camel-example-routetemplate/readme.adoc
index 4aa2f92..3cb8476 100644
--- a/examples/camel-example-routetemplate/readme.adoc
+++ b/examples/camel-example-routetemplate/readme.adoc
@@ -1,6 +1,12 @@
== Camel Example Route Template
-TODO: Update
+This examples shows how to use Route Templates (parameterized routes) to specify a skeleton route
+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 example runs standalone via Camel Main in the `MyApplication.java` source file.
=== How to run
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 d39aad9..955b0a2 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
@@ -29,10 +29,10 @@
public static void main(String[] args) throws Exception {
// use Camels Main class
Main main = new Main();
- // add listener that create routes from the template
- main.addMainListener(new MyMainListener());
// 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);
// 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/java/org/apache/camel/example/MyConfiguration.java b/examples/camel-example-routetemplate/src/main/java/org/apache/camel/example/MyConfiguration.java
new file mode 100644
index 0000000..a3aa603
--- /dev/null
+++ b/examples/camel-example-routetemplate/src/main/java/org/apache/camel/example/MyConfiguration.java
@@ -0,0 +1,43 @@
+/*
+ * 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.CamelContext;
+
+public class MyConfiguration {
+
+ /**
+ * Configure and adds routes from route templates.
+ *
+ * The method name <tt>configureRouteTemplates</tt> is detected from camel-main
+ * and invoked after routes and route templates has been loaded which allows
+ * to create and add routes from the route templates during bootstrap
+ */
+ public void configureRouteTemplates(CamelContext context) {
+ // create two routes from the template
+ context.addRouteFromTemplate("myTemplate")
+ .parameter("name", "one")
+ .parameter("greeting", "Hello")
+ .build();
+
+ context.addRouteFromTemplate("myTemplate")
+ .parameter("name", "two")
+ .parameter("greeting", "Bonjour")
+ .parameter("myPeriod", "5s")
+ .build();
+ }
+}
diff --git a/examples/camel-example-routetemplate/src/main/java/org/apache/camel/example/MyMainListener.java b/examples/camel-example-routetemplate/src/main/java/org/apache/camel/example/MyMainListener.java
deleted file mode 100644
index 959b234..0000000
--- a/examples/camel-example-routetemplate/src/main/java/org/apache/camel/example/MyMainListener.java
+++ /dev/null
@@ -1,38 +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.main.BaseMainSupport;
-import org.apache.camel.main.MainListenerSupport;
-
-public class MyMainListener extends MainListenerSupport {
-
- @Override
- public void beforeStart(BaseMainSupport main) {
- // create two routes from the template
- main.getCamelContext().addRouteFromTemplate("myTemplate")
- .parameter("name", "one")
- .parameter("greeting", "Hello")
- .build();
-
- main.getCamelContext().addRouteFromTemplate("myTemplate")
- .parameter("name", "two")
- .parameter("greeting", "Bonjour")
- .parameter("myPeriod", "5s")
- .build();
- }
-}
diff --git a/examples/camel-example-routetemplate/src/main/java/org/apache/camel/example/MyRouteTemplates.java b/examples/camel-example-routetemplate/src/main/java/org/apache/camel/example/MyRouteTemplates.java
index 79cba25..6040577 100644
--- a/examples/camel-example-routetemplate/src/main/java/org/apache/camel/example/MyRouteTemplates.java
+++ b/examples/camel-example-routetemplate/src/main/java/org/apache/camel/example/MyRouteTemplates.java
@@ -18,14 +18,24 @@
import org.apache.camel.builder.RouteBuilder;
+/**
+ * Route templates using {@link RouteBuilder} which allows
+ * us to define a number of templates (parameterized routes)
+ * which we can create routes from.
+ */
public class MyRouteTemplates extends RouteBuilder {
@Override
public void configure() throws Exception {
+ // create a route template with the given name
routeTemplate("myTemplate")
+ // here we define the required input parameters (can have default values)
.templateParameter("name")
.templateParameter("greeting")
.templateParameter("myPeriod", "3s")
+ // here comes the route in the template
+ // notice how we use {{name}} to refer to the template parameters
+ // we can also use {{propertyName}} to refer to property placeholders
.from("timer:{{name}}?period={{myPeriod}}")
.setBody(simple("{{greeting}} ${body}"))
.log("${body}");