forked from quarkus-qe/beefy-scenarios
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkus-qe#210 from pjgg/feat/kamelet
Add Kamelet module
- Loading branch information
Showing
11 changed files
with
292 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,24 @@ | ||
# Quarkus - Kamelet | ||
|
||
Quarkus-kamelet provide you support to interacting with Camel routes templates. | ||
The aim of this module is to cover the following Kamelet scenarios: | ||
* Camel producers, those scenarios where your service produces events and are consumed by a camel route | ||
* Camel consumers, those scenarios where your service consumes a camel route | ||
* Chain routes multiples routes | ||
* Load application properties as routes bodies | ||
* Validate Kamelet resources as ocp/k8s kamelet yamls(routes-temapltes, routes-bindings...) | ||
|
||
Project folder structure | ||
|
||
* `/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,32 @@ | ||
<?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>org.apache.camel.quarkus</groupId> | ||
<artifactId>camel-quarkus-timer</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.camel.quarkus</groupId> | ||
<artifactId>camel-quarkus-direct</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> |
51 changes: 51 additions & 0 deletions
51
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,51 @@ | ||
package io.quarkus.qe.kamelet; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.GET; | ||
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.ConsumerTemplate; | ||
import org.apache.camel.FluentProducerTemplate; | ||
|
||
@Path("/kamelet") | ||
public class KameletResource { | ||
|
||
@Inject | ||
FluentProducerTemplate fluentProducerTemplate; | ||
|
||
@Inject | ||
ConsumerTemplate consumerTemplate; | ||
|
||
@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); | ||
} | ||
|
||
@Path("/timer") | ||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public Integer consumeFromKamelet() { | ||
return consumerTemplate.receiveBody("kamelet:tick", 10000, Integer.class); | ||
} | ||
|
||
@Path("/property") | ||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String bodyFromApplicationProperty() { | ||
return fluentProducerTemplate.to("kamelet:setBodyFromProperties").request(String.class); | ||
} | ||
|
||
@Path("/chain") | ||
@POST | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String kameletChain(String message) { | ||
return fluentProducerTemplate.to("direct:chain").withBody(message).request(String.class); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
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,35 @@ | ||
package io.quarkus.qe.kamelet; | ||
|
||
import org.apache.camel.Exchange; | ||
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}}"); | ||
|
||
routeTemplate("tick") | ||
.from("timer:{{routeId}}?repeatCount=1&delay=-1") | ||
.setBody().exchangeProperty(Exchange.TIMER_COUNTER) | ||
.to("kamelet:sink"); | ||
|
||
routeTemplate("setBodyFromProperties") | ||
.templateParameter("bodyValueFromProperty") | ||
.from("kamelet:source") | ||
.setBody().constant("Hello {{bodyValueFromProperty}}"); | ||
|
||
routeTemplate("echo") | ||
.templateParameter("prefix") | ||
.templateParameter("suffix") | ||
.from("kamelet:source") | ||
.setBody().simple("{{prefix}} ${body} {{suffix}}"); | ||
|
||
from("direct:chain") | ||
.to("kamelet:echo/1?prefix=Camel Quarkus&suffix=Chained") | ||
.to("kamelet:echo/2?prefix=Hello&suffix=Route"); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
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,4 @@ | ||
# kamelet.names, must match with kamelets prefix name, ex: {prefix}.kamelet.yaml | ||
quarkus.camel.kamelet.names = logger, fresh-beer | ||
|
||
camel.kamelet.setBodyFromProperties.bodyValueFromProperty=World from property |
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 { | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
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,52 @@ | ||
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 testKameletProducerHelloWorld() { | ||
String message = "World"; | ||
|
||
RestAssured.given() | ||
.contentType(ContentType.TEXT) | ||
.body(message) | ||
.post("/kamelet/produce") | ||
.then() | ||
.statusCode(200) | ||
.body(is("Hello " + message)); | ||
} | ||
|
||
@Test | ||
public void testKameletTimerConsumer() { | ||
RestAssured.get("/kamelet/timer") | ||
.then() | ||
.statusCode(200) | ||
.body(is("1")); | ||
} | ||
|
||
@Test | ||
public void testKameletWithProperties() { | ||
RestAssured.get("/kamelet/property") | ||
.then() | ||
.statusCode(200) | ||
.body(is("Hello World from property")); | ||
} | ||
|
||
@Test | ||
public void testKameletChain() { | ||
RestAssured.given() | ||
.contentType(ContentType.TEXT) | ||
.body("Kamelet") | ||
.post("/kamelet/chain") | ||
.then() | ||
.statusCode(200) | ||
.body(is("Hello Camel Quarkus Kamelet Chained Route")); | ||
} | ||
} |
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