-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pablo gonzalez granados
committed
May 19, 2021
1 parent
71bd24a
commit 01e6b15
Showing
11 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Quarkus - Kamelet | ||
|
||
The aim of this module is to cover all kamelet scenarios. | ||
|
||
* `/resources/kamelets` contains kamelets resources as templates or KameletBindings. Also, there are groovy scripts | ||
in order to instantiate these templates by your self (as an example). | ||
|
||
* `io.quarkus.qe.kamelet.KameletRoutes` contains templates that could be invoked (tested) directly by code. So is not | ||
need it to be deployed into ocp or some other platform. | ||
|
||
### Recommended Readings | ||
[Kamelet introduction](https://camel.apache.org/camel-k/latest/kamelets/kamelets-user.html) | ||
|
||
[Kamelets developer guide](https://camel.apache.org/camel-k/latest/kamelets/kamelets-dev.html) | ||
|
||
[Camel-Quarkus first steps](https://camel.apache.org/camel-quarkus/latest/user-guide/first-steps.html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.quarkus.qe</groupId> | ||
<artifactId>beefy-scenarios</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>023-quarkus-kamelet</artifactId> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.camel.quarkus</groupId> | ||
<artifactId>camel-quarkus-kamelet</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-jsonb</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
25 changes: 25 additions & 0 deletions
25
023-quarkus-kamelet/src/main/java/io/quarkus/qe/kamelet/KameletResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.quarkus.qe.kamelet; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.apache.camel.FluentProducerTemplate; | ||
|
||
@Path("/kamelet") | ||
public class KameletResource { | ||
|
||
@Inject | ||
FluentProducerTemplate fluentProducerTemplate; | ||
|
||
@Path("/produce") | ||
@POST | ||
@Consumes(MediaType.TEXT_PLAIN) | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String produceToKamelet(String message) { | ||
return fluentProducerTemplate.toF("kamelet:setBody/test?bodyValue=%s", message).request(String.class); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
023-quarkus-kamelet/src/main/java/io/quarkus/qe/kamelet/KameletRoutes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.quarkus.qe.kamelet; | ||
|
||
import org.apache.camel.builder.RouteBuilder; | ||
|
||
public class KameletRoutes extends RouteBuilder { | ||
|
||
@Override | ||
public void configure() throws Exception { | ||
routeTemplate("setBody") | ||
.templateParameter("bodyValue") | ||
.from("kamelet:source") | ||
.setBody().constant("Hello {{bodyValue}}"); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
023-quarkus-kamelet/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# kamelet.names, must match with kamelets prefix name, ex: {prefix}.kamelet.yaml | ||
quarkus.camel.kamelet.names = logger, fresh-beer |
3 changes: 3 additions & 0 deletions
3
023-quarkus-kamelet/src/main/resources/kamelets/fresh-beer-integration-example.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package kamelets | ||
|
||
from('kamelet:beer-source').log('${body}') |
27 changes: 27 additions & 0 deletions
27
023-quarkus-kamelet/src/main/resources/kamelets/fresh-beer.Kamelet.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
apiVersion: camel.apache.org/v1alpha1 | ||
kind: Kamelet | ||
metadata: | ||
name: beer-source | ||
labels: | ||
camel.apache.org/kamelet.type: "source" | ||
spec: | ||
definition: | ||
title: "Beer Source" | ||
description: "Retrieve a random beer from catalog" | ||
properties: | ||
period: | ||
title: Period | ||
description: The interval between two events | ||
type: integer | ||
default: 1000 | ||
types: | ||
out: | ||
mediaType: application/json | ||
flow: | ||
from: | ||
uri: timer:tick | ||
parameters: | ||
period: "#property:period" | ||
steps: | ||
- to: "https://random-data-api.com/api/beer/random_beer" | ||
- to: "kamelet:sink" |
39 changes: 39 additions & 0 deletions
39
023-quarkus-kamelet/src/main/resources/kamelets/logger.kamelet.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
apiVersion: camel.apache.org/v1alpha1 | ||
kind: Kamelet | ||
metadata: | ||
labels: | ||
camel.apache.org/kamelet.type: "sink" | ||
camel.apache.org/kamelet.name: "log" | ||
camel.apache.org/kamelet.version: "v1alpha1" | ||
spec: | ||
definition: | ||
title: "Logger" | ||
description: "Logger" | ||
properties: | ||
loggerName: | ||
title: Name of the logging category | ||
description: Name of the logging category | ||
type: string | ||
default: "logger" | ||
showAll: | ||
title: Show All | ||
description: Show All | ||
type: boolean | ||
default: false | ||
multiLine: | ||
title: Multi Line | ||
description: Multi Line | ||
type: boolean | ||
default: false | ||
dependencies: | ||
- "camel:log" | ||
flow: | ||
from: | ||
uri: "kamelet:source" | ||
steps: | ||
- to: | ||
uri: "log" | ||
properties: | ||
loggerName: "{{loggerName}}" | ||
showAll: "{{showAll}}" | ||
multiline: "{{multiLine}}" |
8 changes: 8 additions & 0 deletions
8
023-quarkus-kamelet/src/test/java/io/quarkus/qe/kamelet/KameletIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.quarkus.qe.kamelet; | ||
|
||
import io.quarkus.test.junit.NativeImageTest; | ||
|
||
@NativeImageTest | ||
class KameletIT extends KameletTest { | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
023-quarkus-kamelet/src/test/java/io/quarkus/qe/kamelet/KameletTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.quarkus.qe.kamelet; | ||
|
||
import static org.hamcrest.Matchers.is; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.restassured.RestAssured; | ||
import io.restassured.http.ContentType; | ||
|
||
@QuarkusTest | ||
class KameletTest { | ||
@Test | ||
public void testKameletHelloWorld() { | ||
String message = "World"; | ||
|
||
RestAssured.given() | ||
.contentType(ContentType.TEXT) | ||
.body(message) | ||
.post("/kamelet/produce") | ||
.then() | ||
.statusCode(200) | ||
.body(is("Hello " + message)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters