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/08/11 14:03:58 UTC

[camel-examples] branch master updated (1f8c031 -> 52ef848)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel-examples.git.


    from 1f8c031  log4j v1 was removed from camel bom
     new 9c509ae  CAMEL-14297: add example for RouteBuilderConfigurer in lamvda style.
     new 52ef848  Regen

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 examples/README.adoc                               |  4 ++-
 .../pom.xml                                        |  6 ++---
 examples/camel-example-main-lambda/readme.adoc     | 31 ++++++++++++++++++++++
 .../org/apache/camel/example/MyApplication.java    |  4 +--
 .../main/java/org/apache/camel/example/MyBean.java |  0
 .../org/apache/camel/example/MyConfiguration.java  | 15 +++++++++--
 .../src/main/resources/application.properties      | 21 ++++++++-------
 .../src/main/resources/logback.xml                 |  0
 examples/pom.xml                                   |  1 +
 9 files changed, 63 insertions(+), 19 deletions(-)
 copy examples/{camel-example-main => camel-example-main-lambda}/pom.xml (95%)
 create mode 100644 examples/camel-example-main-lambda/readme.adoc
 copy examples/{camel-example-main-xml => camel-example-main-lambda}/src/main/java/org/apache/camel/example/MyApplication.java (93%)
 copy examples/{camel-example-main => camel-example-main-lambda}/src/main/java/org/apache/camel/example/MyBean.java (100%)
 copy examples/{camel-example-main => camel-example-main-lambda}/src/main/java/org/apache/camel/example/MyConfiguration.java (70%)
 copy examples/{camel-example-routetemplate => camel-example-main-lambda}/src/main/resources/application.properties (72%)
 copy examples/{camel-example-routetemplate => camel-example-main-lambda}/src/main/resources/logback.xml (100%)


[camel-examples] 02/02: Regen

Posted by da...@apache.org.
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

commit 52ef848040283b20251493ae35ba5ce0193a85ed
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Aug 11 16:03:44 2020 +0200

    Regen
---
 examples/README.adoc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/examples/README.adoc b/examples/README.adoc
index afd87b2..d013a7e 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: 73 (0 deprecated)
+Number of Examples: 74 (0 deprecated)
 
 [width="100%",cols="4,2,4",options="header"]
 |===
@@ -43,6 +43,8 @@ Number of Examples: 73 (0 deprecated)
 
 | link:camel-example-main-health/readme.adoc[Main Health] (camel-example-main-health) | Beginner | An example for showing standalone Camel with Health Checks
 
+| link:camel-example-main-lambda/readme.adoc[Main Lambda] (camel-example-main-lambda) | Beginner | Camel routes lambda style
+
 | link:camel-example-main-tiny/readme.adoc[Main Tiny] (camel-example-main-tiny) | Beginner | An example for showing standalone Camel with as few JARs on classpath as possible
 
 | link:camel-example-main-xml/readme.adoc[Main Xml] (camel-example-main-xml) | Beginner | An example for showing standalone Camel using XML


[camel-examples] 01/02: CAMEL-14297: add example for RouteBuilderConfigurer in lamvda style.

Posted by da...@apache.org.
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

commit 9c509ae3d5b8aa0048e53fde23e0d5d37ff5f54d
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Aug 11 15:25:33 2020 +0200

    CAMEL-14297: add example for RouteBuilderConfigurer in lamvda style.
---
 examples/camel-example-main-lambda/pom.xml         | 101 +++++++++++++++++++++
 examples/camel-example-main-lambda/readme.adoc     |  31 +++++++
 .../org/apache/camel/example/MyApplication.java    |  40 ++++++++
 .../main/java/org/apache/camel/example/MyBean.java |  36 ++++++++
 .../org/apache/camel/example/MyConfiguration.java  |  48 ++++++++++
 .../src/main/resources/application.properties      |  35 +++++++
 .../src/main/resources/logback.xml                 |  30 ++++++
 examples/pom.xml                                   |   1 +
 8 files changed, 322 insertions(+)

diff --git a/examples/camel-example-main-lambda/pom.xml b/examples/camel-example-main-lambda/pom.xml
new file mode 100644
index 0000000..55fe167
--- /dev/null
+++ b/examples/camel-example-main-lambda/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-main-lambda</artifactId>
+    <packaging>jar</packaging>
+    <name>Camel :: Example :: Main :: Lambda</name>
+    <description>Camel routes lambda style</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-main-lambda/readme.adoc b/examples/camel-example-main-lambda/readme.adoc
new file mode 100644
index 0000000..e55faea
--- /dev/null
+++ b/examples/camel-example-main-lambda/readme.adoc
@@ -0,0 +1,31 @@
+== Camel Example Main Lambda
+
+This example demonstrates how to use `RouteBuilderConfigurer` as a way of defining Camel routes
+using lambda style.
+
+     rb -> rb.from("timer:foo").log("Hello Lambda");
+
+The `RouteBuilderConfigurer` is a functional interface that makes defining routes with lambda style
+easy. All you need to do is to create a method that returns `RouteBuilderConfigurer` and mark
+the method with `@BindToRegistry` or if using Spring Boot `@Bean` or `@Produce` for CDI/Quarkus.
+
+See the `MyConfiguration.java` in this example how this class is the configuration class and where
+routes are defined.
+
+Multiple routes can be defined by having multiple methods.
+
+=== 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-main-lambda/src/main/java/org/apache/camel/example/MyApplication.java b/examples/camel-example-main-lambda/src/main/java/org/apache/camel/example/MyApplication.java
new file mode 100644
index 0000000..1013f33
--- /dev/null
+++ b/examples/camel-example-main-lambda/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();
+        // lets use a configuration class (you can specify multiple classes)
+        // (properties are automatic loaded from application.properties)
+        // the configuration class has the configuration and also the routes to be used
+        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-main-lambda/src/main/java/org/apache/camel/example/MyBean.java b/examples/camel-example-main-lambda/src/main/java/org/apache/camel/example/MyBean.java
new file mode 100644
index 0000000..1e1bdb8
--- /dev/null
+++ b/examples/camel-example-main-lambda/src/main/java/org/apache/camel/example/MyBean.java
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+public class MyBean {
+
+    private String hi;
+    private String bye;
+
+    public MyBean(String hi, String bye) {
+        this.hi = hi;
+        this.bye = bye;
+    }
+
+    public String hello() {
+        return hi + " how are you?";
+    }
+
+    public String bye() {
+        return bye + " World";
+    }
+}
diff --git a/examples/camel-example-main-lambda/src/main/java/org/apache/camel/example/MyConfiguration.java b/examples/camel-example-main-lambda/src/main/java/org/apache/camel/example/MyConfiguration.java
new file mode 100644
index 0000000..32a8b14
--- /dev/null
+++ b/examples/camel-example-main-lambda/src/main/java/org/apache/camel/example/MyConfiguration.java
@@ -0,0 +1,48 @@
+/*
+ * 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.BindToRegistry;
+import org.apache.camel.PropertyInject;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.builder.RouteBuilderConfigurer;
+
+/**
+ * Class to configure the Camel application.
+ */
+public class MyConfiguration {
+
+    @BindToRegistry
+    public MyBean myBean(@PropertyInject("hi") String hi, @PropertyInject("bye") String bye) {
+        // this will create an instance of this bean with the name of the method (eg myBean)
+        return new MyBean(hi, bye);
+    }
+
+    /**
+     * Here we define a route as a method that returns a RouteBuilderConfigurer instance.
+     * This allows us to use lambda style.
+     */
+    @BindToRegistry
+    public RouteBuilderConfigurer myRoute() {
+        return rb -> rb.from("quartz:foo?cron={{myCron}}")
+                .bean("myBean", "hello")
+                .log("${body}")
+                .bean("myBean", "bye")
+                .log("${body}");
+    }
+
+}
diff --git a/examples/camel-example-main-lambda/src/main/resources/application.properties b/examples/camel-example-main-lambda/src/main/resources/application.properties
new file mode 100644
index 0000000..4da5cc9
--- /dev/null
+++ b/examples/camel-example-main-lambda/src/main/resources/application.properties
@@ -0,0 +1,35 @@
+## ---------------------------------------------------------------------------
+## 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
+
+# extended runtime statistics about bean introspection usage (java reflection)
+camel.main.bean-introspection-extended-statistics=true
+camel.main.bean-introspection-logging-level=INFO
+
+# to configure the camel quartz component
+# here we can configure the options on the component level (and we can use dash-naming-style)
+camel.component.quartz.start-delayed-seconds = 3
+
+# properties used in the route
+myCron = 0/2 * * * * ?
+
+# application properties
+hi = Hello
+bye = Bye
diff --git a/examples/camel-example-main-lambda/src/main/resources/logback.xml b/examples/camel-example-main-lambda/src/main/resources/logback.xml
new file mode 100644
index 0000000..a798d0b
--- /dev/null
+++ b/examples/camel-example-main-lambda/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 caab63b..2798530 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -125,6 +125,7 @@
         <module>camel-example-main-artemis</module>
         <module>camel-example-main-endpointdsl</module>
         <module>camel-example-main-health</module>
+        <module>camel-example-main-lambda</module>
         <module>camel-example-main-tiny</module>
         <module>camel-example-main-xml</module>
         <module>camel-example-management</module>