Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions kamelet-chucknorris/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
34 changes: 29 additions & 5 deletions kamelet-chucknorris/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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 -->
Expand Down Expand Up @@ -90,6 +109,7 @@
<version>${log4j2-version}</version>
<scope>runtime</scope>
</dependency>

<!-- for testing -->
<dependency>
<groupId>org.apache.camel</groupId>
Expand All @@ -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>
Expand Down
8 changes: 6 additions & 2 deletions kamelet-chucknorris/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- route:
from:
uri: kamelet:chuck-norris-source
steps:
- log: "${body}"
6 changes: 0 additions & 6 deletions kamelet-chucknorris/src/main/resources/camel/my-route.xml

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion kamelet-chucknorris/src/main/resources/log4j2.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ void should_use_a_simple_kamelet() {

@Override
protected void configure(MainConfigurationProperties configuration) {
configuration.withRoutesIncludePattern("camel/*");
configuration.withRoutesIncludePattern("camel/*.yaml");
}
}
Loading