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/05/18 14:17:03 UTC

[camel-examples] branch master updated (d9ddf2a -> 55e4281)

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 d9ddf2a  Turn off JMX for example
     new 56ff7ba  CAMEL-15068: camel-example-main-endpointdsl - Add example using Endpoing DSL
     new 55e4281  CAMEL-15068: camel-example-main-endpointdsl - Add example using Endpoing DSL

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                                        | 29 +++++++++++-----------
 .../readme.adoc                                    |  9 +++----
 .../org/apache/camel/example/MyApplication.java    |  0
 .../main/java/org/apache/camel/example/MyBean.java |  6 ++---
 .../org/apache/camel/example/MyRouteBuilder.java   | 23 ++++++++++++++---
 .../src/main/resources/application.properties      | 14 ++++++++---
 .../src/main/resources/logback.xml                 |  0
 examples/pom.xml                                   |  1 +
 9 files changed, 54 insertions(+), 32 deletions(-)
 copy examples/{camel-example-main => camel-example-main-endpointdsl}/pom.xml (80%)
 copy examples/{camel-example-main-tiny => camel-example-main-endpointdsl}/readme.adoc (62%)
 copy examples/{camel-example-reactive-executor-vertx => camel-example-main-endpointdsl}/src/main/java/org/apache/camel/example/MyApplication.java (100%)
 copy examples/{camel-example-main-tiny => camel-example-main-endpointdsl}/src/main/java/org/apache/camel/example/MyBean.java (91%)
 copy examples/{camel-example-main-tiny => camel-example-main-endpointdsl}/src/main/java/org/apache/camel/example/MyRouteBuilder.java (50%)
 copy examples/{camel-example-reactive-executor-vertx => camel-example-main-endpointdsl}/src/main/resources/application.properties (80%)
 copy examples/{camel-example-main => camel-example-main-endpointdsl}/src/main/resources/logback.xml (100%)


[camel-examples] 01/02: CAMEL-15068: camel-example-main-endpointdsl - Add example using Endpoing DSL

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 56ff7ba87b57a923fcf6188c695b3433c09f5ba3
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon May 18 16:06:57 2020 +0200

    CAMEL-15068: camel-example-main-endpointdsl - Add example using Endpoing DSL
---
 examples/camel-example-main-endpointdsl/pom.xml    | 102 +++++++++++++++++++++
 .../camel-example-main-endpointdsl/readme.adoc     |  23 +++++
 .../org/apache/camel/example/MyApplication.java    |  38 ++++++++
 .../main/java/org/apache/camel/example/MyBean.java |  38 ++++++++
 .../org/apache/camel/example/MyRouteBuilder.java   |  32 +++++++
 .../src/main/resources/application.properties      |  37 ++++++++
 .../src/main/resources/logback.xml                 |  30 ++++++
 examples/pom.xml                                   |   1 +
 8 files changed, 301 insertions(+)

diff --git a/examples/camel-example-main-endpointdsl/pom.xml b/examples/camel-example-main-endpointdsl/pom.xml
new file mode 100644
index 0000000..02365bf
--- /dev/null
+++ b/examples/camel-example-main-endpointdsl/pom.xml
@@ -0,0 +1,102 @@
+<?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.4.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>camel-example-main-endpointdsl</artifactId>
+    <packaging>jar</packaging>
+    <name>Camel :: Example :: Main :: Endpoint DSL</name>
+    <description>An example for showing standalone Camel with Endpoint DSL</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-main</artifactId>
+        </dependency>
+        <!-- we use the endpoint-dsl -->
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-endpointdsl</artifactId>
+        </dependency>
+        <!-- we use these 2 camel components in this example -->
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-bean</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-timer</artifactId>
+        </dependency>
+
+        <!-- logging -->
+        <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>
+            <!-- to run the application -->
+            <plugin>
+                <groupId>org.apache.camel</groupId>
+                <artifactId>camel-maven-plugin</artifactId>
+                <version>${camel.version}</version>
+                <configuration>
+                    <mainClass>org.apache.camel.example.MyApplication</mainClass>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
diff --git a/examples/camel-example-main-endpointdsl/readme.adoc b/examples/camel-example-main-endpointdsl/readme.adoc
new file mode 100644
index 0000000..d2584c6
--- /dev/null
+++ b/examples/camel-example-main-endpointdsl/readme.adoc
@@ -0,0 +1,23 @@
+== Camel Example Main Endpoint DSL
+
+This example shows how to use the endpoint DSL in your Camel routes
+to define endpoints using type safe fluent builders, which are Java methods
+that are compiled.
+
+Notice how you can configure Camel in the `application.properties` file.
+
+=== 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-endpointdsl/src/main/java/org/apache/camel/example/MyApplication.java b/examples/camel-example-main-endpointdsl/src/main/java/org/apache/camel/example/MyApplication.java
new file mode 100644
index 0000000..496b37d
--- /dev/null
+++ b/examples/camel-example-main-endpointdsl/src/main/java/org/apache/camel/example/MyApplication.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.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();
+        // and add the routes (you can specify multiple classes)
+        main.configure().addRoutesBuilder(MyRouteBuilder.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-endpointdsl/src/main/java/org/apache/camel/example/MyBean.java b/examples/camel-example-main-endpointdsl/src/main/java/org/apache/camel/example/MyBean.java
new file mode 100644
index 0000000..348a0a6
--- /dev/null
+++ b/examples/camel-example-main-endpointdsl/src/main/java/org/apache/camel/example/MyBean.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.spi.Configurer;
+
+@Configurer
+public class MyBean {
+
+    private String hi;
+
+    public String getHi() {
+        return hi;
+    }
+
+    public void setHi(String hi) {
+        this.hi = hi;
+    }
+
+    public String hello() {
+        return hi + " how are you?";
+    }
+
+}
diff --git a/examples/camel-example-main-endpointdsl/src/main/java/org/apache/camel/example/MyRouteBuilder.java b/examples/camel-example-main-endpointdsl/src/main/java/org/apache/camel/example/MyRouteBuilder.java
new file mode 100644
index 0000000..41e0bf9
--- /dev/null
+++ b/examples/camel-example-main-endpointdsl/src/main/java/org/apache/camel/example/MyRouteBuilder.java
@@ -0,0 +1,32 @@
+/*
+ * 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.endpoint.EndpointRouteBuilder;
+
+/**
+ * To use the endpoint DSL then we must extend EndpointRouteBuilder instead of RouteBuilder
+ */
+public class MyRouteBuilder extends EndpointRouteBuilder {
+
+    @Override
+    public void configure() throws Exception {
+        from(timer("foo").period("{{myPeriod}}"))
+            .to(bean("myBean").method("hello"))
+            .log("${body}");
+    }
+}
diff --git a/examples/camel-example-main-endpointdsl/src/main/resources/application.properties b/examples/camel-example-main-endpointdsl/src/main/resources/application.properties
new file mode 100644
index 0000000..0726a51
--- /dev/null
+++ b/examples/camel-example-main-endpointdsl/src/main/resources/application.properties
@@ -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.
+## ---------------------------------------------------------------------------
+
+# to configure camel main
+# here you can configure options on camel main (see MainConfigurationProperties class)
+camel.main.name = MyCoolCamel
+
+# enable tracing
+### camel.main.tracing = true
+
+# you can also configure camel context directly
+# camel.context.shutdown-strategy.shutdown-now-on-timeout = false
+
+# you can configure whether OS environment should override (=2 which is default) or as fallback (=1)
+### camel.component.properties.environment-variable-mode=1
+
+# properties used in the route
+myPeriod = 1000
+
+# configure beans
+camel.beans.myBean = #class:org.apache.camel.example.MyBean
+camel.beans.myBean.hi = Hello
+
diff --git a/examples/camel-example-main-endpointdsl/src/main/resources/logback.xml b/examples/camel-example-main-endpointdsl/src/main/resources/logback.xml
new file mode 100644
index 0000000..a798d0b
--- /dev/null
+++ b/examples/camel-example-main-endpointdsl/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 00cd97c..d978ee4 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -126,6 +126,7 @@
         <module>camel-example-loan-broker-jms</module>
         <module>camel-example-main</module>
         <module>camel-example-main-artemis</module>
+        <module>camel-example-main-endpointdsl</module>
         <module>camel-example-main-tiny</module>
         <module>camel-example-main-xml</module>
         <module>camel-example-management</module>


[camel-examples] 02/02: CAMEL-15068: camel-example-main-endpointdsl - Add example using Endpoing DSL

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 55e4281339ea907cb2be6d94dd1734530cdef908
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon May 18 16:16:47 2020 +0200

    CAMEL-15068: camel-example-main-endpointdsl - Add example using Endpoing DSL
---
 examples/README.adoc                                     |  4 +++-
 .../src/main/java/org/apache/camel/example/MyBean.java   |  6 ++----
 .../java/org/apache/camel/example/MyRouteBuilder.java    | 16 ++++++++++++++--
 .../src/main/resources/application.properties            |  3 ---
 4 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/examples/README.adoc b/examples/README.adoc
index 3d235bc..27c6321 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: 84 (0 deprecated)
+Number of Examples: 85 (0 deprecated)
 
 [width="100%",cols="4,2,4",options="header"]
 |===
@@ -37,6 +37,8 @@ Number of Examples: 84 (0 deprecated)
 
 | link:camel-example-main/readme.adoc[Main] (camel-example-main) | Beginner | An example for showing standalone Camel
 
+| link:camel-example-main-endpointdsl/readme.adoc[Main Endpointdsl] (camel-example-main-endpointdsl) | Beginner | An example for showing standalone Camel with Endpoint DSL
+
 | 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
diff --git a/examples/camel-example-main-endpointdsl/src/main/java/org/apache/camel/example/MyBean.java b/examples/camel-example-main-endpointdsl/src/main/java/org/apache/camel/example/MyBean.java
index 348a0a6..c8f350f 100644
--- a/examples/camel-example-main-endpointdsl/src/main/java/org/apache/camel/example/MyBean.java
+++ b/examples/camel-example-main-endpointdsl/src/main/java/org/apache/camel/example/MyBean.java
@@ -16,12 +16,10 @@
  */
 package org.apache.camel.example;
 
-import org.apache.camel.spi.Configurer;
-
-@Configurer
 public class MyBean {
 
     private String hi;
+    private int counter;
 
     public String getHi() {
         return hi;
@@ -32,7 +30,7 @@ public class MyBean {
     }
 
     public String hello() {
-        return hi + " how are you?";
+        return hi + " how are you? I am called " + ++counter + " times";
     }
 
 }
diff --git a/examples/camel-example-main-endpointdsl/src/main/java/org/apache/camel/example/MyRouteBuilder.java b/examples/camel-example-main-endpointdsl/src/main/java/org/apache/camel/example/MyRouteBuilder.java
index 41e0bf9..c1c14cd 100644
--- a/examples/camel-example-main-endpointdsl/src/main/java/org/apache/camel/example/MyRouteBuilder.java
+++ b/examples/camel-example-main-endpointdsl/src/main/java/org/apache/camel/example/MyRouteBuilder.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.example;
 
+import org.apache.camel.BeanScope;
 import org.apache.camel.builder.endpoint.EndpointRouteBuilder;
 
 /**
@@ -25,8 +26,19 @@ public class MyRouteBuilder extends EndpointRouteBuilder {
 
     @Override
     public void configure() throws Exception {
-        from(timer("foo").period("{{myPeriod}}"))
-            .to(bean("myBean").method("hello"))
+        // the endpoint-dsl allows to define endpoints in type safe fluent builders
+        // here we configure the time and bean endpoint
+
+        from(timer("foo")
+                .period("{{myPeriod}}") // here we use {{ }} to refer to properties from application.properties
+                .includeMetadata(false)
+                .repeatCount(123))
+            .to(bean("org.apache.camel.example.MyBean")
+                    .method("hello")
+                    // try change this to Prototype scope
+                    .scope(BeanScope.Singleton)
+                    // we can configure advanced options
+                    .advanced().parameters("hi", "Davs"))
             .log("${body}");
     }
 }
diff --git a/examples/camel-example-main-endpointdsl/src/main/resources/application.properties b/examples/camel-example-main-endpointdsl/src/main/resources/application.properties
index 0726a51..5d62b5d 100644
--- a/examples/camel-example-main-endpointdsl/src/main/resources/application.properties
+++ b/examples/camel-example-main-endpointdsl/src/main/resources/application.properties
@@ -31,7 +31,4 @@ camel.main.name = MyCoolCamel
 # properties used in the route
 myPeriod = 1000
 
-# configure beans
-camel.beans.myBean = #class:org.apache.camel.example.MyBean
-camel.beans.myBean.hi = Hello