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 3966b06 Added kamelet chuck norris example
3966b06 is described below
commit 3966b06888a02ab720222706e50d715448e8d26e
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Jun 4 07:12:36 2021 +0200
Added kamelet chuck norris example
---
README.adoc | 4 +-
kamelet-chucknorris/pom.xml | 128 +++++++++++++++++++++
kamelet-chucknorris/readme.adoc | 30 +++++
.../main/java/sample/camel/MyCamelApplication.java | 37 ++++++
.../src/main/java/sample/camel/MyRoute.java | 33 ++++++
.../src/main/resources/application.yaml | 22 ++++
.../kamelets/chuck-norris-source.kamelet.yaml | 42 +++++++
.../sample/camel/MyCamelApplicationJUnit5Test.java | 47 ++++++++
pom.xml | 1 +
9 files changed, 343 insertions(+), 1 deletion(-)
diff --git a/README.adoc b/README.adoc
index cf62d46..78d8d89 100644
--- a/README.adoc
+++ b/README.adoc
@@ -27,7 +27,7 @@ readme's instructions.
=== Examples
// examples: START
-Number of Examples: 48 (0 deprecated)
+Number of Examples: 49 (0 deprecated)
[width="100%",cols="4,2,4",options="header"]
|===
@@ -41,6 +41,8 @@ Number of Examples: 48 (0 deprecated)
| link:jira/README.adoc[Jira] (jira) | Beginner | An example that uses Jira
Camel API
+| link:kamelet-chucknorris/readme.adoc[Kamelet Chucknorris]
(kamelet-chucknorris) | Beginner | How easy it is to create your own Kamelets
+
| link:load-balancer-eip/README.adoc[Load Balancer Eip] (load-balancer-eip) |
Beginner | An example showing Load Balancer EIP with Camel and Spring Boot
| link:pojo/README.adoc[Pojo] (pojo) | Beginner | An example showing how to
work with Camel POJO routing with Spring Boot
diff --git a/kamelet-chucknorris/pom.xml b/kamelet-chucknorris/pom.xml
new file mode 100644
index 0000000..0de504a
--- /dev/null
+++ b/kamelet-chucknorris/pom.xml
@@ -0,0 +1,128 @@
+<?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.11.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-example-spring-boot-kamelet-chucknorris</artifactId>
+ <name>Camel SB Examples :: Spring Boot :: Kamelet Chuck Norris</name>
+ <description>How easy it is to create your own Kamelets</description>
+
+ <properties>
+ <category>Beginner</category>
+
+ <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>${camel-version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+
+ <!-- Spring Boot -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter</artifactId>
+ </dependency>
+
+ <!-- Camel -->
+ <dependency>
+ <groupId>org.apache.camel.springboot</groupId>
+ <artifactId>camel-spring-boot-starter</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.springboot</groupId>
+ <artifactId>camel-kamelet-starter</artifactId>
+ </dependency>
+ <!-- yaml dsl -->
+ <dependency>
+ <groupId>org.apache.camel.springboot</groupId>
+ <artifactId>camel-yaml-dsl-starter</artifactId>
+ </dependency>
+ <!-- these dependencies are used by the kamelet -->
+ <dependency>
+ <groupId>org.apache.camel.springboot</groupId>
+ <artifactId>camel-timer-starter</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.springboot</groupId>
+ <artifactId>camel-http-starter</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.springboot</groupId>
+ <artifactId>camel-jsonpath-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>
+ </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>
+ </plugins>
+ </build>
+</project>
diff --git a/kamelet-chucknorris/readme.adoc b/kamelet-chucknorris/readme.adoc
new file mode 100644
index 0000000..b076612
--- /dev/null
+++ b/kamelet-chucknorris/readme.adoc
@@ -0,0 +1,30 @@
+== Camel Example Kamelet Chuck Norris
+
+=== Introduction
+
+This example shows how you can build a simple Kamelet and use with your Camel
applications.
+
+The kamelet is created as a YAML file in the `src/main/resources/kamelets'
directory.
+We have developed a Chuck Norris Kamelet that periodically gets a joke from
the Chuck Norris internet database.
+
+A Camel routes is coded in Java in the
`src/main/java/samples/camel/MyRoute.java` file
+that uses the Kamelet, and log the result from the Kamelet to the console.
+
+=== How to run
+
+You can run this example using
+
+ mvn spring-boot: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/kamelet-chucknorris/src/main/java/sample/camel/MyCamelApplication.java
b/kamelet-chucknorris/src/main/java/sample/camel/MyCamelApplication.java
new file mode 100644
index 0000000..6c91e07
--- /dev/null
+++ b/kamelet-chucknorris/src/main/java/sample/camel/MyCamelApplication.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 MyCamelApplication {
+
+ /**
+ * A main method to start this application.
+ */
+ public static void main(String[] args) {
+ SpringApplication.run(MyCamelApplication.class, args);
+ }
+
+}
+//CHECKSTYLE:ON
diff --git a/kamelet-chucknorris/src/main/java/sample/camel/MyRoute.java
b/kamelet-chucknorris/src/main/java/sample/camel/MyRoute.java
new file mode 100644
index 0000000..8258444
--- /dev/null
+++ b/kamelet-chucknorris/src/main/java/sample/camel/MyRoute.java
@@ -0,0 +1,33 @@
+/*
+ * 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.apache.camel.builder.RouteBuilder;
+import org.springframework.stereotype.Component;
+
+/**
+ * Java route that uses the kamelet and logs the response.
+ */
+@Component
+public class MyRoute extends RouteBuilder {
+
+ @Override
+ public void configure() throws Exception {
+ from("kamelet:chuck-norris-source")
+ .log("${body}");
+ }
+}
diff --git a/kamelet-chucknorris/src/main/resources/application.yaml
b/kamelet-chucknorris/src/main/resources/application.yaml
new file mode 100644
index 0000000..ccd8fc8
--- /dev/null
+++ b/kamelet-chucknorris/src/main/resources/application.yaml
@@ -0,0 +1,22 @@
+#
+# 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.
+#
+
+camel:
+ springboot:
+ name: ChuckCamel
+ # keep the application running
+ main-run-controller: true
diff --git
a/kamelet-chucknorris/src/main/resources/kamelets/chuck-norris-source.kamelet.yaml
b/kamelet-chucknorris/src/main/resources/kamelets/chuck-norris-source.kamelet.yaml
new file mode 100644
index 0000000..75be465
--- /dev/null
+++
b/kamelet-chucknorris/src/main/resources/kamelets/chuck-norris-source.kamelet.yaml
@@ -0,0 +1,42 @@
+apiVersion: camel.apache.org/v1alpha1
+kind: Kamelet
+metadata:
+ name: chuck-norris-source
+ annotations:
+ camel.apache.org/kamelet.support.level: "Preview"
+ camel.apache.org/catalog.version: "main-SNAPSHOT"
+ camel.apache.org/kamelet.icon:
data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pg0KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDE5LjAuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPg0KPHN2ZyB2ZXJzaW9uPSIxLjEiIGlkPSJDYXBhXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4Ig0KCSB2aWV3Qm94PSIwIDAgNTEyIDUxMiIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDA
[...]
+ camel.apache.org/provider: "Apache Software Foundation"
+ camel.apache.org/kamelet.group: "Chuck Norris"
+ labels:
+ camel.apache.org/kamelet.type: "source"
+spec:
+ definition:
+ title: "Chuck Norris Source"
+ description: |-
+ Gets peridically Chuck Norris jokes from http://www.icndb.com/
+ type: object
+ properties:
+ period:
+ title: Period
+ description: The interval (msec) to wait before getting the next joke
+ type: integer
+ default: 10000
+ types:
+ out:
+ mediaType: text/plain
+ dependencies:
+ - "camel:kamelet"
+ - "camel:timer"
+ - "camel:http"
+ - "camel:jsonpath"
+ flow:
+ from:
+ uri: "timer:chuck"
+ parameters:
+ period: "{{period}}"
+ steps:
+ - to: "http://api.icndb.com/jokes/random"
+ - set-body:
+ jsonpath: "$.value.joke"
+ - to: "kamelet:sink"
\ No newline at end of file
diff --git
a/kamelet-chucknorris/src/test/java/sample/camel/MyCamelApplicationJUnit5Test.java
b/kamelet-chucknorris/src/test/java/sample/camel/MyCamelApplicationJUnit5Test.java
new file mode 100644
index 0000000..21c7a2a
--- /dev/null
+++
b/kamelet-chucknorris/src/test/java/sample/camel/MyCamelApplicationJUnit5Test.java
@@ -0,0 +1,47 @@
+/*
+ * 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.jupiter.api.Assertions.assertTrue;
+
+@CamelSpringBootTest
+@SpringBootTest(classes = MyCamelApplication.class)
+public class MyCamelApplicationJUnit5Test {
+
+ @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));
+ }
+
+}
diff --git a/pom.xml b/pom.xml
index ab1df60..03f7715 100644
--- a/pom.xml
+++ b/pom.xml
@@ -54,6 +54,7 @@
<module>jira</module>
<module>kafka-avro</module>
<module>kafka-offsetrepository</module>
+ <module>kamelet-chucknorris</module>
<module>load-balancer-eip</module>
<module>master</module>
<module>metrics</module>