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/02 16:50:27 UTC

[camel-examples] branch master updated: CAMEL-14963: Route Template example.

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 1717e6d  CAMEL-14963: Route Template example.
1717e6d is described below

commit 1717e6dbf93008b98eaa3260ad0c7494f464d3b3
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Jul 2 18:50:09 2020 +0200

    CAMEL-14963: Route Template example.
---
 examples/README.adoc                               |   4 +-
 examples/camel-example-routetemplate/pom.xml       | 101 +++++++++++++++++++++
 examples/camel-example-routetemplate/readme.adoc   |  19 ++++
 .../src/main/data/foo.properties                   |  18 ++++
 .../org/apache/camel/example/MyApplication.java    |  40 ++++++++
 .../org/apache/camel/example/MyMainListener.java   |  38 ++++++++
 .../org/apache/camel/example/MyRouteTemplates.java |  33 +++++++
 .../src/main/resources/application.properties      |  25 +++++
 .../src/main/resources/logback.xml                 |  30 ++++++
 examples/pom.xml                                   |   1 +
 10 files changed, 308 insertions(+), 1 deletion(-)

diff --git a/examples/README.adoc b/examples/README.adoc
index d7e14a9..e16f327 100644
--- a/examples/README.adoc
+++ b/examples/README.adoc
@@ -11,7 +11,7 @@ View the individual example READMEs for details.
 == Examples
 
 // examples: START
-Number of Examples: 88 (0 deprecated)
+Number of Examples: 89 (0 deprecated)
 
 [width="100%",cols="4,2,4",options="header"]
 |===
@@ -50,6 +50,8 @@ Number of Examples: 88 (0 deprecated)
 | link:camel-example-pojo-messaging/README.adoc[POJO Routing] (camel-example-pojo-messaging) | Beginner | An example showing how to produce and consume messages from Camel endpoints using annotated POJOs
     
 
+| link:camel-example-routetemplate/readme.adoc[Routetemplate] (camel-example-routetemplate) | Beginner | How to use route templates (parameterized routes)
+
 | link:camel-example-servlet-tomcat/README.adoc[Servlet Tomcat] (camel-example-servlet-tomcat) | Beginner | An example using Camel Servlet with Apache Tomcat
 
 | link:camel-example-spring/README.adoc[Spring] (camel-example-spring) | Beginner | An example showing how to work with Camel and Spring
diff --git a/examples/camel-example-routetemplate/pom.xml b/examples/camel-example-routetemplate/pom.xml
new file mode 100644
index 0000000..62dcb4e
--- /dev/null
+++ b/examples/camel-example-routetemplate/pom.xml
@@ -0,0 +1,101 @@
+<?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.5.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>camel-example-routetemplate</artifactId>
+    <packaging>jar</packaging>
+    <name>Camel :: Example :: RouteTemplate</name>
+    <description>How to use route templates (parameterized routes)</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-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-routetemplate/readme.adoc b/examples/camel-example-routetemplate/readme.adoc
new file mode 100644
index 0000000..4aa2f92
--- /dev/null
+++ b/examples/camel-example-routetemplate/readme.adoc
@@ -0,0 +1,19 @@
+== Camel Example Route Template
+
+TODO: Update
+
+=== How to run
+
+You can run this example using
+
+    mvn camel:run
+
+=== 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-routetemplate/src/main/data/foo.properties b/examples/camel-example-routetemplate/src/main/data/foo.properties
new file mode 100644
index 0000000..b43e6bc
--- /dev/null
+++ b/examples/camel-example-routetemplate/src/main/data/foo.properties
@@ -0,0 +1,18 @@
+## ---------------------------------------------------------------------------
+## 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/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
new file mode 100644
index 0000000..d39aad9
--- /dev/null
+++ b/examples/camel-example-routetemplate/src/main/java/org/apache/camel/example/MyApplication.java
@@ -0,0 +1,40 @@
+/*
+ * 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();
+        // add listener that create routes from the template
+        main.addMainListener(new MyMainListener());
+        // and add route templates via routes builder
+        main.configure().addRoutesBuilder(MyRouteTemplates.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/MyMainListener.java b/examples/camel-example-routetemplate/src/main/java/org/apache/camel/example/MyMainListener.java
new file mode 100644
index 0000000..959b234
--- /dev/null
+++ b/examples/camel-example-routetemplate/src/main/java/org/apache/camel/example/MyMainListener.java
@@ -0,0 +1,38 @@
+/*
+ * 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
new file mode 100644
index 0000000..79cba25
--- /dev/null
+++ b/examples/camel-example-routetemplate/src/main/java/org/apache/camel/example/MyRouteTemplates.java
@@ -0,0 +1,33 @@
+/*
+ * 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 MyRouteTemplates extends RouteBuilder {
+
+    @Override
+    public void configure() throws Exception {
+        routeTemplate("myTemplate")
+            .templateParameter("name")
+            .templateParameter("greeting")
+            .templateParameter("myPeriod", "3s")
+            .from("timer:{{name}}?period={{myPeriod}}")
+                .setBody(simple("{{greeting}} ${body}"))
+                .log("${body}");
+    }
+}
diff --git a/examples/camel-example-routetemplate/src/main/resources/application.properties b/examples/camel-example-routetemplate/src/main/resources/application.properties
new file mode 100644
index 0000000..df19913
--- /dev/null
+++ b/examples/camel-example-routetemplate/src/main/resources/application.properties
@@ -0,0 +1,25 @@
+## ---------------------------------------------------------------------------
+## 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 = MyCoolCamel
+
+
+# application properties
+hi = Hello
+
diff --git a/examples/camel-example-routetemplate/src/main/resources/logback.xml b/examples/camel-example-routetemplate/src/main/resources/logback.xml
new file mode 100644
index 0000000..a798d0b
--- /dev/null
+++ b/examples/camel-example-routetemplate/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 1b23b45..d3ec65f 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -145,6 +145,7 @@
         <module>camel-example-rest-karaf-osgi-activator</module>
         -->
         <module>camel-example-route-throttling</module>
+        <module>camel-example-routetemplate</module>
         <module>camel-example-servlet-rest-blueprint</module>
         <module>camel-example-servlet-tomcat</module>
         <module>camel-example-splunk</module>