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


The following commit(s) were added to refs/heads/main by this push:
     new 0688f74  Add yaml based kamelet example
0688f74 is described below

commit 0688f74e188cecd253afddd8677f462473fa76fa
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Wed May 19 15:13:16 2021 +0200

    Add yaml based kamelet example
---
 examples/README.adoc                               |   4 +-
 examples/kamelet-yaml/README.adoc                  |  44 +++++++
 examples/kamelet-yaml/pom.xml                      | 127 +++++++++++++++++++++
 .../src/main/resources/application.properties      |  27 +++++
 .../src/main/resources/camel/my-route.yaml         |   6 +
 .../kamelets/earthquake-source.kamelet.yaml        |  91 +++++++++++++++
 .../kamelet-yaml/src/main/resources/logback.xml    |  30 +++++
 examples/pom.xml                                   |   1 +
 8 files changed, 329 insertions(+), 1 deletion(-)

diff --git a/examples/README.adoc b/examples/README.adoc
index 8bf2918..bcb07ae 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: 91 (0 deprecated)
+Number of Examples: 92 (0 deprecated)
 
 [width="100%",cols="4,2,4",options="header"]
 |===
@@ -49,6 +49,8 @@ Number of Examples: 91 (0 deprecated)
 
 | link:kamelet/README.adoc[Kamelet] (kamelet) | Beginner | How to use Kamelets
 
+| link:kamelet-yaml/README.adoc[Kamelet Yaml] (kamelet-yaml) | Beginner | How 
to use Kamelets with YAML DSL
+
 | link:main/README.adoc[Main] (main) | Beginner | An example for showing 
standalone Camel
 
 | link:main-endpointdsl/README.adoc[Main Endpointdsl] (main-endpointdsl) | 
Beginner | An example for showing standalone Camel with Endpoint DSL
diff --git a/examples/kamelet-yaml/README.adoc 
b/examples/kamelet-yaml/README.adoc
new file mode 100644
index 0000000..b018f7e
--- /dev/null
+++ b/examples/kamelet-yaml/README.adoc
@@ -0,0 +1,44 @@
+== Camel Example Kamelet YAML
+
+=== Introduction
+
+This example shows how to use ready to use Kamelets you can find at the
+https://camel.apache.org/camel-kamelets/latest/[Camel Kamelet Catalog].
+
+We are using the _Earthquake Source_ Kamelet which we have downloaded and 
stored
+in the `src/main/resources/kamelet` directory.
+
+Then we added the needed Camel components (you can find the list inside the 
kamelet YAML file).
+
+A Camel routes is _coded_ in the `my-camel.yaml` file using the YAML DSL that 
uses the kamelet,
+and log the result from the kamelet to the console.
+
+The example has no Java code at all, and is started via Camel's own `Main` 
class from `camel-main` JAR.
+
+=== Build
+
+You will need to compile this example first:
+
+[source,sh]
+----
+$ mvn compile
+----
+
+=== Run
+
+You can run this example using
+
+[source,sh]
+----
+$ mvn camel:run
+----
+
+=== Help and contributions
+
+If you hit any problem using Camel or have some feedback, then please
+https://camel.apache.org/community/support/[let us know].
+
+We also love contributors, so
+https://camel.apache.org/community/contributing/[get involved] :-)
+
+The Camel riders!
diff --git a/examples/kamelet-yaml/pom.xml b/examples/kamelet-yaml/pom.xml
new file mode 100644
index 0000000..ecc5f32
--- /dev/null
+++ b/examples/kamelet-yaml/pom.xml
@@ -0,0 +1,127 @@
+<?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.10.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>camel-example-kamelet-yaml</artifactId>
+    <packaging>jar</packaging>
+    <name>Camel :: Example :: Kamelet YAML</name>
+    <description>How to use Kamelets with YAML 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-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-main</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-kamelet</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-yaml-dsl</artifactId>
+        </dependency>
+
+        <!-- earthquake-source kamelet -->
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-caffeine</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-http</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-jackson</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-jsonpath</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-timer</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.main.Main</mainClass>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
diff --git a/examples/kamelet-yaml/src/main/resources/application.properties 
b/examples/kamelet-yaml/src/main/resources/application.properties
new file mode 100644
index 0000000..9e18b36
--- /dev/null
+++ b/examples/kamelet-yaml/src/main/resources/application.properties
@@ -0,0 +1,27 @@
+## ---------------------------------------------------------------------------
+## 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
+camel.main.name = MyEarthQuake
+
+# load all kind of routes from this folder
+camel.main.routes-include-pattern = classpath:camel/*
+
+# turn on lightweight mode
+camel.main.lightweight = true
+
+
diff --git a/examples/kamelet-yaml/src/main/resources/camel/my-route.yaml 
b/examples/kamelet-yaml/src/main/resources/camel/my-route.yaml
new file mode 100644
index 0000000..b6eb2df
--- /dev/null
+++ b/examples/kamelet-yaml/src/main/resources/camel/my-route.yaml
@@ -0,0 +1,6 @@
+- route:
+    from: "kamelet:earthquake-source"
+    steps:
+      - unmarshal:
+          json: {}
+      - log: "Earthquake with magnitude ${body[properties][mag]} at 
${body[properties][place]}"
diff --git 
a/examples/kamelet-yaml/src/main/resources/kamelets/earthquake-source.kamelet.yaml
 
b/examples/kamelet-yaml/src/main/resources/kamelets/earthquake-source.kamelet.yaml
new file mode 100755
index 0000000..5335c1d
--- /dev/null
+++ 
b/examples/kamelet-yaml/src/main/resources/kamelets/earthquake-source.kamelet.yaml
@@ -0,0 +1,91 @@
+apiVersion: camel.apache.org/v1alpha1
+kind: Kamelet
+metadata:
+  name: earthquake-source
+  annotations:
+    camel.apache.org/kamelet.icon: 
"data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9JzEwMHB4JyB3aWR0aD0nMTAwcHgnICBmaWxsPSIjMDAwMDAwIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2ZXJzaW9uPSIxLjEiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm94PSIwIDAgMTAwLjAwMyA3OS45OTciIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMCAwIDEwMC4wMDMgNzkuOTk3IiB4bWw6c3BhY2U9InByZXNlcnZlIj48cGF0aCBkPSJNODEuNjUzLDQyLjk0Yy0xLjM4NywwLTIuNjY2LDAuNzY3LTMuMzE1LDEuOTkyTDcyLjk0Miw1NS4xbC02Lj
 [...]
+    camel.apache.org/provider: "Apache Software Foundation"
+    camel.apache.org/kamelet.group: "Earthquake"
+  labels:
+    camel.apache.org/kamelet.type: "source"
+    camel.apache.org/kamelet.verified: "true"
+spec:
+  definition:
+    title: Earthquake Source
+    description: |-
+      Get data about current earthquake events happening in the world using 
the USGS API
+    type: object
+    properties:
+      period:
+        title: Period between Polls
+        description: The interval between fetches to the earthquake API in 
milliseconds
+        type: integer
+        default: 60000
+      lookAhead:
+        title: Look-ahead Minutes
+        description: The amount of minutes to look ahead when starting the 
integration afresh
+        type: integer
+        default: 120
+  types:
+    out:
+      mediaType: application/json
+  dependencies:
+    - "camel:caffeine"
+    - "camel:http"
+    - "camel:kamelet"
+    - "camel:core"
+    - "camel:jackson"
+    - "camel:jsonpath"
+    - "camel:timer"
+  flow:
+    from:
+      uri: "timer:earthquake"
+      parameters:
+        period: "{{period}}"
+      steps:
+      - set-header:
+          name: CamelCaffeineAction
+          constant: GET
+      - tod: "caffeine-cache:cache-${routeId}?key=lastUpdate"
+      - choice:
+          when:
+          - simple: "${header.CamelCaffeineActionHasResult}"
+            steps:
+            - set-property:
+                name: lastUpdate
+                simple: "${body}"
+          otherwise:
+            steps:
+            - set-property:
+                name: lastUpdate
+                simple: 
"${date-with-timezone:now-{{lookAhead}}m:UTC:yyyy-MM-dd'T'HH:mm:ss.SSS}"
+      - set-header:
+          name: CamelHttpMethod
+          constant: GET
+      - tod: 
"https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&updatedafter=${exchangeProperty.lastUpdate}&orderby=time-asc";
+      - remove-header:
+          header-name: CamelHttpMethod
+      - unmarshal:
+          json: {}
+      - set-property:
+          name: generated
+          simple: "${body[metadata][generated]}"
+      - set-property:
+          name: lastUpdate
+          simple: 
"${date-with-timezone:exchangeProperty.generated:UTC:yyyy-MM-dd'T'HH:mm:ss.SSS}"
+      - claim-check:
+          operation: Push
+      - set-body:
+          exchange-property: lastUpdate
+      - set-header:
+          name: CamelCaffeineAction
+          constant: PUT
+      - tod: "caffeine-cache:cache-${routeId}?key=lastUpdate"
+      - claim-check:
+          operation: Pop
+      - split:
+          jsonpath: "$.features[*]"
+          steps:
+            - marshal:
+                json: {}
+            - to: "kamelet:sink"
diff --git a/examples/kamelet-yaml/src/main/resources/logback.xml 
b/examples/kamelet-yaml/src/main/resources/logback.xml
new file mode 100644
index 0000000..a798d0b
--- /dev/null
+++ b/examples/kamelet-yaml/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 5aaf3e5..0fb3900 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -123,6 +123,7 @@
         <module>jooq</module>
         <module>kafka</module>
         <module>kamelet</module>
+        <module>kamelet-yaml</module>
         <module>kotlin</module>
         <module>loan-broker-cxf</module>
         <module>loadbalancing</module>

Reply via email to