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-spring-boot-examples.git


The following commit(s) were added to refs/heads/main by this push:
     new 75ec77b  CAMEL-17300: camel-spring-boot - Add route reload example
75ec77b is described below

commit 75ec77bf8347155043ff69dac59b1ea38cb6ace4
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Dec 9 16:52:13 2021 +0100

    CAMEL-17300: camel-spring-boot - Add route reload example
---
 README.adoc                                        |   4 +-
 pom.xml                                            |   1 +
 route-reload/pom.xml                               | 141 +++++++++++++++++++++
 route-reload/readme.adoc                           |  25 ++++
 .../java/sample/camel/SampleCamelApplication.java  |  37 ++++++
 .../src/main/resources/application.properties      |  28 ++++
 route-reload/src/main/resources/camel/my-route.xml |  37 ++++++
 .../sample/camel/SampleCamelApplicationTest.java   |  46 +++++++
 8 files changed, 318 insertions(+), 1 deletion(-)

diff --git a/README.adoc b/README.adoc
index cf1bafc..e5a7d98 100644
--- a/README.adoc
+++ b/README.adoc
@@ -27,7 +27,7 @@ readme's instructions.
 === Examples
 
 // examples: START
-Number of Examples: 53 (0 deprecated)
+Number of Examples: 54 (0 deprecated)
 
 [width="100%",cols="4,2,4",options="header"]
 |===
@@ -53,6 +53,8 @@ Number of Examples: 53 (0 deprecated)
 
 | link:rest-swagger-simple/README.adoc[REST Swagger] (rest-swagger-simple) | 
Beginner | This example shows how to call a Rest service defined using Swagger 
specification
 
+| link:route-reload/readme.adoc[Spring Boot Route Reload] (route-reload) | 
Beginner | Live reload of routes if file is updated and saved
+
 | link:routes-configuration/readme.adoc[Routes Configuration] 
(routes-configuration) | Beginner | Example with global routes configuration 
for error handling
 
 | link:routetemplate/readme.adoc[Routetemplate] (routetemplate) | Beginner | 
How to use route templates (parameterized routes)
diff --git a/pom.xml b/pom.xml
index 854f8c5..dbde619 100644
--- a/pom.xml
+++ b/pom.xml
@@ -72,6 +72,7 @@
                <module>rest-openapi-simple</module>
                <module>rest-openapi-springdoc</module>
                <module>routetemplate</module>
+               <module>route-reload</module>
                <module>routes-configuration</module>
                <module>servicecall</module>
                <module>supervising-route-controller</module>
diff --git a/route-reload/pom.xml b/route-reload/pom.xml
new file mode 100644
index 0000000..d4e6168
--- /dev/null
+++ b/route-reload/pom.xml
@@ -0,0 +1,141 @@
+<?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.springboot.example</groupId>
+        <artifactId>examples</artifactId>
+        <version>3.14.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>camel-example-spring-boot-route-reload</artifactId>
+    <name>Camel SB Examples :: Route Reload</name>
+    <description>Live reload of routes if file is updated and 
saved</description>
+
+    <properties>
+        <category>Beginner</category>
+        <title>Spring Boot Route Reload</title>
+
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+        <spring.boot-version>${spring-boot-version}</spring.boot-version>
+    </properties>
+
+    <dependencyManagement>
+        <dependencies>
+            <!-- Spring Boot BOM -->
+            <dependency>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-dependencies</artifactId>
+                <version>${spring.boot-version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+            <!-- Camel BOM -->
+            <dependency>
+                <groupId>org.apache.camel.springboot</groupId>
+                <artifactId>camel-spring-boot-bom</artifactId>
+                <version>${project.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <dependencies>
+
+        <!-- Spring Boot -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-actuator</artifactId>
+        </dependency>
+
+        <!-- Camel -->
+        <dependency>
+            <groupId>org.apache.camel.springboot</groupId>
+            <artifactId>camel-spring-boot-xml-starter</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.springboot</groupId>
+            <artifactId>camel-xml-jaxb-dsl-starter</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.springboot</groupId>
+            <artifactId>camel-stream-starter</artifactId>
+        </dependency>
+
+        <!-- test -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test-spring-junit5</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-management</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.junit.vintage</groupId>
+            <artifactId>junit-vintage-engine</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <version>${spring-boot-version}</version>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>repackage</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+
+            <plugin>
+                <groupId>org.apache.camel</groupId>
+                <artifactId>camel-maven-plugin</artifactId>
+                <version>${camel-version}</version>
+                <!-- allows to fail if not all routes are fully covered during 
testing -->
+                <!--
+                        <configuration>
+                          <failOnError>true</failOnError>
+                        </configuration>
+                -->
+            </plugin>
+        </plugins>
+    </build>
+</project>
diff --git a/route-reload/readme.adoc b/route-reload/readme.adoc
new file mode 100644
index 0000000..6ee075d
--- /dev/null
+++ b/route-reload/readme.adoc
@@ -0,0 +1,25 @@
+== Route Reload Example
+
+This example shows how to use route reloading. This feature is watching a 
directory folder
+for file changes, and then automatic trigger reload of the running routes in 
the Camel application.
+
+The example generates messages using timer trigger, writes them to standard 
output.
+
+=== How to run
+
+You can run this example using
+
+    mvn spring-boot:run
+
+Then you can edit the `src/main/resources/camel/my-route.xml` file and save, 
to trigger
+automatic reloading.
+
+=== 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/route-reload/src/main/java/sample/camel/SampleCamelApplication.java 
b/route-reload/src/main/java/sample/camel/SampleCamelApplication.java
new file mode 100644
index 0000000..a51e48a
--- /dev/null
+++ b/route-reload/src/main/java/sample/camel/SampleCamelApplication.java
@@ -0,0 +1,37 @@
+/*
+ * 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 sample.camel;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+//CHECKSTYLE:OFF
+/**
+ * A sample Spring Boot application that starts the Camel routes.
+ */
+@SpringBootApplication
+public class SampleCamelApplication {
+
+    /**
+     * A main method to start this application.
+     */
+    public static void main(String[] args) {
+        SpringApplication.run(SampleCamelApplication.class, args);
+    }
+
+}
+//CHECKSTYLE:ON
diff --git a/route-reload/src/main/resources/application.properties 
b/route-reload/src/main/resources/application.properties
new file mode 100644
index 0000000..42fe96a
--- /dev/null
+++ b/route-reload/src/main/resources/application.properties
@@ -0,0 +1,28 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+# the name of Camel
+camel.springboot.name = ReloadCamel
+
+# turn on route reloading on file changes
+camel.springboot.routes-reload-enabled = true
+# the base directory to watch
+camel.springboot.routes-reload-directory = src/main/resources/camel
+# pattern(s) for files to watch
+camel.springboot.routes-reload-pattern = *.xml
+
+
diff --git a/route-reload/src/main/resources/camel/my-route.xml 
b/route-reload/src/main/resources/camel/my-route.xml
new file mode 100644
index 0000000..d3798bf
--- /dev/null
+++ b/route-reload/src/main/resources/camel/my-route.xml
@@ -0,0 +1,37 @@
+<?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.
+
+-->
+<routes xmlns="http://camel.apache.org/schema/spring";>
+
+  <!-- run this application with mvn spring-boot:run and then update and save 
this file
+       to see live changes in Camel -->
+
+    <route id="hello">
+      <from uri="timer:hello?period=2000"/>
+      <transform>
+        <constant>Hi World</constant>
+      </transform>
+      <filter>
+        <simple>${body} contains 'foo'</simple>
+        <to uri="log:foo?showHeaders=true"/>
+      </filter>
+      <to uri="stream:out"/>
+    </route>
+
+</routes>
diff --git 
a/route-reload/src/test/java/sample/camel/SampleCamelApplicationTest.java 
b/route-reload/src/test/java/sample/camel/SampleCamelApplicationTest.java
new file mode 100644
index 0000000..1915afc
--- /dev/null
+++ b/route-reload/src/test/java/sample/camel/SampleCamelApplicationTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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 sample.camel;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.NotifyBuilder;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import static org.junit.Assert.assertTrue;
+
+@CamelSpringBootTest
+@SpringBootTest(classes = SampleCamelApplication.class)
+public class SampleCamelApplicationTest {
+
+    @Autowired
+    private CamelContext camelContext;
+
+    @Test
+    public void shouldProduceMessages() throws Exception {
+        // we expect that one or more messages is automatic done by the Camel
+        // route as it uses a timer to trigger
+        NotifyBuilder notify = new 
NotifyBuilder(camelContext).whenDone(1).create();
+
+        assertTrue(notify.matches(10, TimeUnit.SECONDS));
+    }
+
+}

Reply via email to