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 2021/05/21 09:07:43 UTC
[camel-examples] branch main updated: kamelet-yaml - Download
kamelet online from github
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 0ad6a0d kamelet-yaml - Download kamelet online from github
0ad6a0d is described below
commit 0ad6a0d033902ac409931aeaa0f536be507fc5f7
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri May 21 11:06:48 2021 +0200
kamelet-yaml - Download kamelet online from github
---
examples/kamelet-yaml/README.adoc | 15 ++--
examples/kamelet-yaml/pom.xml | 12 ++-
.../src/main/resources/application.properties | 5 +-
.../kamelets/earthquake-source.kamelet.yaml | 91 ----------------------
4 files changed, 24 insertions(+), 99 deletions(-)
diff --git a/examples/kamelet-yaml/README.adoc b/examples/kamelet-yaml/README.adoc
index 1767566..9f9d721 100644
--- a/examples/kamelet-yaml/README.adoc
+++ b/examples/kamelet-yaml/README.adoc
@@ -5,13 +5,18 @@
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.
+We are using the _Earthquake Source_ Kamelet which we load from github at startup
+with the `camel-resourceresolver-github` JAR.
-Then we added the needed Camel components (you can find the list inside the kamelet YAML file).
+You can also download the Kamelet YAML file from github and save into `src/main/resources/kamelets` folder,
+which the `camel-kamelet` component would automatic load from. If you do that then remove the
+`camel.component.kamelet.location=github:apache:camel-kamelets` from the `application.properties` 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.
+Before the Kamelet is ready to use, we must add the needed Camel components
+(you can find the list inside the kamelet YAML file) to the Maven `pom.xml` file.
+
+A Camel routes is _coded_ in the `my-route.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.
diff --git a/examples/kamelet-yaml/pom.xml b/examples/kamelet-yaml/pom.xml
index 36fe0ae..785e559 100644
--- a/examples/kamelet-yaml/pom.xml
+++ b/examples/kamelet-yaml/pom.xml
@@ -60,16 +60,24 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-main</artifactId>
</dependency>
+ <!-- use YAML DSL for defining Camel routes -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-yaml-dsl</artifactId>
+ </dependency>
+ <!-- Kamelet support -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-kamelet</artifactId>
</dependency>
+ <!-- to automatic download kamelet from github -->
<dependency>
<groupId>org.apache.camel</groupId>
- <artifactId>camel-yaml-dsl</artifactId>
+ <artifactId>camel-resourceresolver-github</artifactId>
</dependency>
- <!-- earthquake-source kamelet -->
+ <!-- earthquake-source Kamelet dependencies that is manually added -->
+ <!-- see inside the kamelet yaml source file where the dependencies are listed -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-caffeine</artifactId>
diff --git a/examples/kamelet-yaml/src/main/resources/application.properties b/examples/kamelet-yaml/src/main/resources/application.properties
index 9e18b36..7360bd7 100644
--- a/examples/kamelet-yaml/src/main/resources/application.properties
+++ b/examples/kamelet-yaml/src/main/resources/application.properties
@@ -18,7 +18,10 @@
# to configure camel main
camel.main.name = MyEarthQuake
-# load all kind of routes from this folder
+# load kamelet online from github from the official Apache Camel Kamelet Catalog
+camel.component.kamelet.location=github:apache:camel-kamelets
+
+# load the Camel routes from this folder
camel.main.routes-include-pattern = classpath:camel/*
# turn on lightweight mode
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
deleted file mode 100755
index 5335c1d..0000000
--- a/examples/kamelet-yaml/src/main/resources/kamelets/earthquake-source.kamelet.yaml
+++ /dev/null
@@ -1,91 +0,0 @@
-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"