This is an automated email from the ASF dual-hosted git repository. apupier pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-examples.git
commit c98209aac437a43c6dd2c4e2957d56834bf53d04 Author: Torsten Mielke <[email protected]> AuthorDate: Thu Sep 17 13:27:37 2026 +0200 CAMEL-22986: Use official kamelets from camel-kamelets catalog JAR Reworked the kamelet-chucknorris example to use the official chuck-norris-source kamelet from the camel-kamelets catalog JAR instead of bundling a custom kamelet YAML file locally. - Added camel-kamelets dependency to load official kamelets from classpath - Converted route definition from XML DSL to YAML DSL - Removed custom chuck-norris-source.kamelet.yaml - Added MyApplication.java for standalone Camel Main bootstrap - Added explicit component dependencies (timer, http, jsonpath) needed by the kamelet at runtime Co-authored-by: Claude Opus 4.6 <[email protected]> --- kamelet-chucknorris/README.adoc | 20 ++++++++--- kamelet-chucknorris/pom.xml | 34 +++++++++++++++--- .../src/main/resources/application.properties | 8 +++-- .../src/main/resources/camel/my-route.xml | 6 ---- .../kamelets/chuck-norris-source.kamelet.yaml | 42 ---------------------- .../src/main/resources/log4j2.properties | 2 +- .../camel/example/KameletChuckNorrisTest.java | 2 +- 7 files changed, 52 insertions(+), 62 deletions(-) diff --git a/kamelet-chucknorris/README.adoc b/kamelet-chucknorris/README.adoc index fd879689..b05d2d93 100644 --- a/kamelet-chucknorris/README.adoc +++ b/kamelet-chucknorris/README.adoc @@ -2,13 +2,23 @@ === Introduction -This example shows how you can build a simple Kamelet and use with your Camel applications. +This example shows how to use an official Kamelet from the +https://camel.apache.org/camel-kamelets/next/[Kamelets Catalog] +in a traditional Maven-based Camel application. -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. +The example uses the +https://camel.apache.org/camel-kamelets/next/chuck-norris-source.html[Chuck Norris Source] +Kamelet which periodically gets a joke from the Chuck Norris internet database. -A Camel routes is _coded_ in the `my-route.xml` file using the XML DSL that uses the Kamelet, -and log the result from the Kamelet to the console. +The official Kamelets are included as a Maven dependency by adding the `camel-kamelets` +JAR to the `pom.xml`. Kamelets are then auto-discovered from the classpath at runtime. + +NOTE: The `camel-kamelets` JAR only contains the Kamelet YAML definitions. You must also +add the Camel component dependencies that the Kamelet uses internally +(e.g. `camel-timer`, `camel-http`, `camel-jsonpath` for the Chuck Norris Kamelet). + +The Camel route is defined in `my-route.camel.yaml` using the YAML DSL and logs +the joke to the console. === Build diff --git a/kamelet-chucknorris/pom.xml b/kamelet-chucknorris/pom.xml index d392469f..bfcb3642 100644 --- a/kamelet-chucknorris/pom.xml +++ b/kamelet-chucknorris/pom.xml @@ -31,7 +31,7 @@ <artifactId>camel-example-kamelet-chucknorris</artifactId> <packaging>jar</packaging> <name>Camel :: Example :: Kamelet :: Chuck Norris</name> - <description>How easy it is to create your own Kamelets</description> + <description>How easy it is to use a Kamelet in your Camel application</description> <properties> <category>Kamelet</category> @@ -47,20 +47,39 @@ <type>pom</type> <scope>import</scope> </dependency> + <dependency> + <groupId>org.apache.camel.kamelets</groupId> + <artifactId>camel-kamelets</artifactId> + <version>${camel-kamelets-catalog-version}</version> + </dependency> </dependencies> </dependencyManagement> <dependencies> - <!-- main to easily run with Kamelets --> + <!-- main dependencies --> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-kamelet-main</artifactId> + <artifactId>camel-core</artifactId> </dependency> - <!-- to use XML DSL --> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-xml-io-dsl</artifactId> + <artifactId>camel-main</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-kamelet</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.kamelets</groupId> + <artifactId>camel-kamelets</artifactId> + </dependency> + + <!-- to use YAML DSL for route definitions --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-yaml-dsl</artifactId> </dependency> <!-- these dependencies are used by the kamelet --> @@ -90,6 +109,7 @@ <version>${log4j2-version}</version> <scope>runtime</scope> </dependency> + <!-- for testing --> <dependency> <groupId>org.apache.camel</groupId> @@ -105,6 +125,10 @@ <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> diff --git a/kamelet-chucknorris/src/main/resources/application.properties b/kamelet-chucknorris/src/main/resources/application.properties index 8945f00b..b33a1fa3 100644 --- a/kamelet-chucknorris/src/main/resources/application.properties +++ b/kamelet-chucknorris/src/main/resources/application.properties @@ -19,6 +19,10 @@ # https://camel.apache.org/components/next/others/main.html camel.main.name = MyKameletCamel -# routes to load -camel.main.routes-include-pattern = camel/*.xml +# routes to load, not needed here as routes from classpath:camel/* are +# automatically loaded +# camel.main.routes-include-pattern = camel/*.yaml + +# configure the period of the Chuck Norris Source Kamelet +camel.kamelet.chuck-norris-source.period=60000 diff --git a/kamelet-chucknorris/src/main/resources/camel/my-route.xml b/kamelet-chucknorris/src/main/resources/camel/my-route.xml deleted file mode 100644 index 3db4a365..00000000 --- a/kamelet-chucknorris/src/main/resources/camel/my-route.xml +++ /dev/null @@ -1,6 +0,0 @@ -<routes xmlns="http://camel.apache.org/schema/spring"> - <route> - <from uri="kamelet:chuck-norris-source"/> - <log message="${body}"/> - </route> -</routes> \ No newline at end of file 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 deleted file mode 100644 index 937f06f5..00000000 --- a/kamelet-chucknorris/src/main/resources/kamelets/chuck-norris-source.kamelet.yaml +++ /dev/null @@ -1,42 +0,0 @@ -apiVersion: camel.apache.org/v1 -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" - template: - from: - uri: "timer:chuck" - parameters: - period: "{{period}}" - steps: - - to: "https://api.chucknorris.io/jokes/random" - - setBody: - jsonpath: "$.value" - - to: "kamelet:sink" diff --git a/kamelet-chucknorris/src/main/resources/log4j2.properties b/kamelet-chucknorris/src/main/resources/log4j2.properties index d9f0508a..c0147f85 100644 --- a/kamelet-chucknorris/src/main/resources/log4j2.properties +++ b/kamelet-chucknorris/src/main/resources/log4j2.properties @@ -18,6 +18,6 @@ appender.out.type = Console appender.out.name = out appender.out.layout.type = PatternLayout -appender.out.layout.pattern = [%30.30t] %-30.30c{1} %-5p %m%n +appender.out.layout.pattern = %d [%20.20t] %-20.20c{1} %-5p %m%n rootLogger.level = INFO rootLogger.appenderRef.out.ref = out diff --git a/kamelet-chucknorris/src/test/java/org/apache/camel/example/KameletChuckNorrisTest.java b/kamelet-chucknorris/src/test/java/org/apache/camel/example/KameletChuckNorrisTest.java index 43ed238e..dea1ca73 100644 --- a/kamelet-chucknorris/src/test/java/org/apache/camel/example/KameletChuckNorrisTest.java +++ b/kamelet-chucknorris/src/test/java/org/apache/camel/example/KameletChuckNorrisTest.java @@ -40,6 +40,6 @@ class KameletChuckNorrisTest extends CamelMainTestSupport { @Override protected void configure(MainConfigurationProperties configuration) { - configuration.withRoutesIncludePattern("camel/*"); + configuration.withRoutesIncludePattern("camel/*.yaml"); } }
