From fa7efdec23d96ffb976e7b1b8dab9c9fd35783c5 Mon Sep 17 00:00:00 2001 From: Christoph Deppisch Date: Thu, 2 Jul 2026 19:31:34 +0200 Subject: [PATCH] feat(#7): Add Camel AWS S3 to Kafka example Co-Authored-By: Claude Opus 4.6 --- apache-camel/camel-aws-s3-kafka/.dockerignore | 5 + .../.mvn/wrapper/maven-wrapper.properties | 4 + apache-camel/camel-aws-s3-kafka/README.md | 216 +++++++++++++ apache-camel/camel-aws-s3-kafka/mvnw | 295 ++++++++++++++++++ apache-camel/camel-aws-s3-kafka/pom.xml | 165 ++++++++++ .../src/main/docker/Dockerfile.jvm | 100 ++++++ .../src/main/docker/Dockerfile.legacy-jar | 96 ++++++ .../src/main/docker/Dockerfile.native | 29 ++ .../src/main/docker/Dockerfile.native-micro | 32 ++ .../src/main/java/org/acme/Routes.java | 25 ++ .../src/main/resources/application.properties | 9 + .../java/org/acme/QuarkusApplicationTest.java | 137 ++++++++ .../src/test/resources/application.properties | 1 + apache-camel/pom.xml | 1 + 14 files changed, 1115 insertions(+) create mode 100644 apache-camel/camel-aws-s3-kafka/.dockerignore create mode 100644 apache-camel/camel-aws-s3-kafka/.mvn/wrapper/maven-wrapper.properties create mode 100644 apache-camel/camel-aws-s3-kafka/README.md create mode 100755 apache-camel/camel-aws-s3-kafka/mvnw create mode 100644 apache-camel/camel-aws-s3-kafka/pom.xml create mode 100644 apache-camel/camel-aws-s3-kafka/src/main/docker/Dockerfile.jvm create mode 100644 apache-camel/camel-aws-s3-kafka/src/main/docker/Dockerfile.legacy-jar create mode 100644 apache-camel/camel-aws-s3-kafka/src/main/docker/Dockerfile.native create mode 100644 apache-camel/camel-aws-s3-kafka/src/main/docker/Dockerfile.native-micro create mode 100644 apache-camel/camel-aws-s3-kafka/src/main/java/org/acme/Routes.java create mode 100644 apache-camel/camel-aws-s3-kafka/src/main/resources/application.properties create mode 100644 apache-camel/camel-aws-s3-kafka/src/test/java/org/acme/QuarkusApplicationTest.java create mode 100644 apache-camel/camel-aws-s3-kafka/src/test/resources/application.properties diff --git a/apache-camel/camel-aws-s3-kafka/.dockerignore b/apache-camel/camel-aws-s3-kafka/.dockerignore new file mode 100644 index 0000000..94810d0 --- /dev/null +++ b/apache-camel/camel-aws-s3-kafka/.dockerignore @@ -0,0 +1,5 @@ +* +!target/*-runner +!target/*-runner.jar +!target/lib/* +!target/quarkus-app/* \ No newline at end of file diff --git a/apache-camel/camel-aws-s3-kafka/.mvn/wrapper/maven-wrapper.properties b/apache-camel/camel-aws-s3-kafka/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..ce33c1c --- /dev/null +++ b/apache-camel/camel-aws-s3-kafka/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,4 @@ +wrapperVersion=3.3.4 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.15/apache-maven-3.9.15-bin.zip +distributionSha256Sum=b0d9292f06c5faded31ddcb6cb69099f316d6fea40a7778624b259bad9fed18a diff --git a/apache-camel/camel-aws-s3-kafka/README.md b/apache-camel/camel-aws-s3-kafka/README.md new file mode 100644 index 0000000..e6fc0de --- /dev/null +++ b/apache-camel/camel-aws-s3-kafka/README.md @@ -0,0 +1,216 @@ +# Apache Camel AWS S3 to Kafka Integration Testing with Citrus + +This example demonstrates how to test Apache Camel routes in Quarkus applications using the Citrus framework with AWS S3 and Kafka integration. The project showcases a Camel route that consumes files from an AWS S3 bucket via the `aws-s3-source` Kamelet, splits each file into individual lines, wraps each line as a JSON event, and produces the resulting events onto a Kafka topic. + +## Why Citrus for AWS S3 Testing? + +Citrus provides built-in support for **LocalStack Testcontainers** through the `@LocalStackContainerSupport` annotation. This makes it straightforward to: + +- Spin up a LocalStack container simulating AWS S3 locally +- Inject dynamic connection properties into the Quarkus application context +- Use Apache Camel's `aws2-s3` component to upload test files through Citrus's `CamelSupport.camel()` DSL + +For Kafka verification, Citrus provides the `@KafkaContainerSupport` annotation and `@KafkaEndpointConfig` - a simple, declarative way to provision Kafka broker infrastructure and configure test endpoints: + +```java +@KafkaContainerSupport(port = 9092, version = "4.2.0") +class QuarkusApplicationTest { + @CitrusEndpoint + @KafkaEndpointConfig(topic = "s3-events") + KafkaEndpoint s3Events; +} +``` + +## What You'll Learn + +By the end of this guide, you'll understand: + +- **Camel S3 via Kamelet**: How to consume S3 files using the `aws-s3-source` Kamelet with LocalStack +- **Splitter EIP**: How to split file content into individual lines and process each as a separate message +- **JSON Transformation**: How to wrap each split line into a JSON event using Simple expressions +- **LocalStack Testcontainers**: How to use `@LocalStackContainerSupport` to start a local S3 service +- **Citrus + Camel S3 Testing**: How to use Camel's `aws2-s3` component through Citrus for uploading files in tests +- **Multi-Protocol Testing**: How to combine S3 (upload) and Kafka (receive/verify) in a single integration test + +## The Application Under Test + +The Quarkus application uses Apache Camel to implement an integration route that bridges AWS S3 and Kafka: + +``` +S3 Bucket (citrus-camel-demo) → Split by newline → Filter empty lines → JSON wrap → Kafka Topic (s3-events) +``` + +### Apache Camel Route + +The application consists of a single Camel route defined in `Routes.java`: + +```java +public class Routes extends EndpointRouteBuilder { + + @Override + public void configure() throws Exception { + from("kamelet:aws-s3-source?" + + "bucketNameOrArn={{aws.s3.bucketNameOrArn}}&" + + "region={{aws.s3.region}}&" + + "overrideEndpoint=true&" + + "forcePathStyle=true&" + + "uriEndpointOverride={{aws.s3.uriEndpointOverride}}&" + + "accessKey={{aws.s3.accessKey}}&" + + "secretKey={{aws.s3.secretKey}}") + .split(body().tokenize("\n")) + .filter(simple("${body} != \"\"")) + .setBody() + .simple(""" + { "message": "${body}" } + """) + .to(kafka("s3-events")); + } +} +``` + +**Route Breakdown:** + +1. **from("kamelet:aws-s3-source?...")**: Consumes files from the S3 bucket using the `aws-s3-source` Kamelet + - `overrideEndpoint=true` and `forcePathStyle=true` enable LocalStack compatibility + - Connection properties are resolved from application properties via Camel property placeholders (`{{...}}`) +2. **.split(body().tokenize("\n"))**: Splits the file content by newline, processing each line as an individual message +3. **.filter(simple("${body} != \"\""))**: Filters out empty lines +4. **.setBody().simple(...)**: Wraps each line in a JSON structure `{ "message": "..." }` +5. **.to(kafka("s3-events"))**: Produces each JSON event to the `s3-events` Kafka topic + +## Understanding the Citrus Test + +The test class `QuarkusApplicationTest` demonstrates how to verify the end-to-end routing behavior using Citrus framework. + +### Test Setup: LocalStack for AWS S3 + +The test uses `@LocalStackContainerSupport` to start a LocalStack container with the S3 service enabled: + +```java +@LocalStackContainerSupport(services = AwsService.S3, + containerLifecycleListener = QuarkusApplicationTest.LocalStackConfigurer.class) +class QuarkusApplicationTest { + + public static class LocalStackConfigurer implements ContainerLifecycleListener { + @Override + public Map started(LocalStackContainer container) { + // Create the S3 bucket + S3Client s3Client = container.getClient(AwsService.S3); + s3Client.createBucket(builder -> builder.bucket(BUCKET_NAME)); + + // Return connection properties for the Camel route + return Map.of( + "aws.s3.bucketNameOrArn", BUCKET_NAME, + "aws.s3.uriEndpointOverride", serviceEndpoint, + "aws.s3.accessKey", container.getAccessKey(), + "aws.s3.secretKey", container.getSecretKey(), + "aws.s3.region", container.getRegion() + ); + } + } +} +``` + +**What's happening here:** + +- `@LocalStackContainerSupport(services = AwsService.S3)`: Starts a LocalStack container with only the S3 service +- `LocalStackConfigurer`: Creates the test bucket and returns dynamic connection properties that override the `application.properties` defaults, ensuring the Camel route connects to the test container + +### Uploading Files via Camel's S3 Component + +The test uses Camel's `aws2-s3` component through `TestActionSupport.camel()` to upload a multi-line file: + +```java +runner.when( + camel() + .send() + .endpoint("aws2-s3://citrus-camel-demo?overrideEndpoint=true&...") + .message() + .fork(true) + .body("Hello Camel!\nHello Citrus!\nHello Quarkus!") + .header("CamelAwsS3Key", "hello.txt") +); +``` + +**What's happening here:** + +- `camel().send()`: Uses Citrus's Camel integration to send a message through a Camel endpoint +- `.endpoint("aws2-s3://...")`: Specifies the Camel S3 endpoint URI with property placeholders pointing to LocalStack +- `.header("CamelAwsS3Key", "hello.txt")`: Sets the S3 object key for the uploaded file +- `.fork(true)`: Sends the message asynchronously so the test can proceed to verify the Kafka output + +### Verifying Kafka Events + +After the S3 file is processed by the Camel route, the test verifies that each line produces a separate JSON event on the Kafka topic: + +```java +@CitrusEndpoint +@KafkaEndpointConfig(topic = "s3-events", consumerGroup = "citrus-consumer-1") +KafkaEndpoint s3Events; + +runner.then( + receive() + .endpoint(s3Events) + .message() + .body("{ \"message\": \"Hello Camel!\" }") +); +``` + +### Test Execution Flow + +1. **WHEN**: Upload a file with 3 lines (`Hello Camel!\nHello Citrus!\nHello Quarkus!`) to the S3 bucket +2. The `aws-s3-source` Kamelet polls the bucket and picks up the file +3. The Splitter EIP splits the file content into 3 individual messages +4. Each line is wrapped as JSON: `{ "message": "Hello Camel!" }` +5. **THEN**: Verify that 3 JSON events arrive on the `s3-events` Kafka topic + +## Key Testing Concepts + +### 1. LocalStack Container Support + +The `@LocalStackContainerSupport` annotation starts a LocalStack container with specific AWS services. The `ContainerLifecycleListener` pattern allows you to perform setup (like creating buckets) and inject dynamic connection properties into the Quarkus application context. + +### 2. Citrus Camel Integration for S3 + +When the test infrastructure (LocalStack) is only accessible through dynamic connection settings, Citrus can leverage Camel's `aws2-s3` component with property placeholders to upload files. This approach reuses the same configuration mechanism as the application route. + +### 3. Property-Based Configuration + +Both the Camel route and the test S3 endpoint use Camel property placeholders (`{{aws.s3.*}}`). The `ContainerLifecycleListener` returns properties that are automatically injected into the Quarkus application context, ensuring consistent configuration between the application and tests. + +### 4. Forked Message Sending + +The `.fork(true)` option is important because the S3 upload and subsequent Kamelet polling happen asynchronously. It ensures the test thread continues to the verification step while the file is being uploaded and processed. + +## Running the Tests + +Execute the tests using Maven: + +```bash +./mvnw clean test +``` + +**What happens during test execution:** + +1. `@LocalStackContainerSupport` starts a LocalStack container with the S3 service +2. `@KafkaContainerSupport` starts a Kafka broker container +3. The `LocalStackConfigurer` creates the S3 bucket and injects connection properties +4. The `KafkaConfigurer` creates the `s3-events` topic +5. Quarkus starts the application with the Camel route connecting to both services +6. The test uploads a multi-line file to S3 and verifies the split events arrive on Kafka + +**Expected output:** +``` +[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 +``` + +As the Citrus test class is an arbitrary JUnit Jupiter test you may also run the test directly from your favorite Java IDE (e.g. Eclipse or IntelliJ). + +## Related Resources + +- [Citrus Framework Documentation](https://citrusframework.org/docs/) +- [Citrus Quarkus Demo](https://github.com/christophd/citrus-demo-quarkus) - Comprehensive examples of Citrus with Quarkus +- [Apache Camel AWS S3 Component](https://camel.apache.org/components/latest/aws2-s3-component.html) - Camel S3 component reference +- [Apache Camel Splitter EIP](https://camel.apache.org/components/latest/eips/split-eip.html) - Splitter EIP +- [Apache Camel Kamelets](https://camel.apache.org/camel-kamelets/latest/) - Kamelet catalog +- [LocalStack](https://localstack.cloud/) - AWS cloud service emulator used in the test diff --git a/apache-camel/camel-aws-s3-kafka/mvnw b/apache-camel/camel-aws-s3-kafka/mvnw new file mode 100755 index 0000000..bd8896b --- /dev/null +++ b/apache-camel/camel-aws-s3-kafka/mvnw @@ -0,0 +1,295 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# 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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.4 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +scriptDir="$(dirname "$0")" +scriptName="$(basename "$0")" + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"$scriptDir/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${scriptName#mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c - >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi + +# Find the actual extracted directory name (handles snapshots where filename != directory name) +actualDistributionDir="" + +# First try the expected directory name (for regular distributions) +if [ -d "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" ]; then + if [ -f "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/bin/$MVN_CMD" ]; then + actualDistributionDir="$distributionUrlNameMain" + fi +fi + +# If not found, search for any directory with the Maven executable (for snapshots) +if [ -z "$actualDistributionDir" ]; then + # enable globbing to iterate over items + set +f + for dir in "$TMP_DOWNLOAD_DIR"/*; do + if [ -d "$dir" ]; then + if [ -f "$dir/bin/$MVN_CMD" ]; then + actualDistributionDir="$(basename "$dir")" + break + fi + fi + done + set -f +fi + +if [ -z "$actualDistributionDir" ]; then + verbose "Contents of $TMP_DOWNLOAD_DIR:" + verbose "$(ls -la "$TMP_DOWNLOAD_DIR")" + die "Could not find Maven distribution directory in extracted archive" +fi + +verbose "Found extracted Maven distribution directory: $actualDistributionDir" +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$actualDistributionDir/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$actualDistributionDir" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/apache-camel/camel-aws-s3-kafka/pom.xml b/apache-camel/camel-aws-s3-kafka/pom.xml new file mode 100644 index 0000000..9ffa107 --- /dev/null +++ b/apache-camel/camel-aws-s3-kafka/pom.xml @@ -0,0 +1,165 @@ + + + 4.0.0 + org.citrusframework.quarkus.examples + camel-aws-s3-kafka + 1.0.0-SNAPSHOT + Citrus Quarkus Examples :: Camel :: AWS S3 Kafka + quarkus + + + 3.15.0 + 21 + UTF-8 + UTF-8 + 5.0.0-M2 + quarkus-bom + io.quarkus.platform + 3.36.2 + 3.5.4 + + true + + + + + + ${quarkus.platform.group-id} + ${quarkus.platform.artifact-id} + ${quarkus.platform.version} + pom + import + + + ${quarkus.platform.group-id} + quarkus-camel-bom + ${quarkus.platform.version} + pom + import + + + + + + + org.apache.camel.quarkus + camel-quarkus-kamelet + + + org.apache.camel.quarkus + camel-quarkus-aws2-s3 + + + org.apache.camel.kamelets + camel-kamelets + + + org.apache.camel.quarkus + camel-quarkus-kafka + + + io.quarkus + quarkus-arc + + + io.quarkus + quarkus-junit + test + + + org.citrusframework + citrus-quarkus + ${citrus.version} + test + + + org.citrusframework + citrus-junit-jupiter + ${citrus.version} + test + + + org.citrusframework + citrus-camel + ${citrus.version} + test + + + org.citrusframework + citrus-kafka + ${citrus.version} + test + + + org.citrusframework + citrus-testcontainers + ${citrus.version} + test + + + + + + + ${quarkus.platform.group-id} + quarkus-maven-plugin + ${quarkus.platform.version} + true + + + maven-compiler-plugin + ${compiler-plugin.version} + + true + + + + maven-surefire-plugin + ${surefire-plugin.version} + + @{argLine} + + org.jboss.logmanager.LogManager + ${maven.home} + + + + + maven-failsafe-plugin + ${surefire-plugin.version} + + + + integration-test + verify + + + + + @{argLine} + + ${project.build.directory}/${project.build.finalName}-runner + org.jboss.logmanager.LogManager + ${maven.home} + + + + + + + + + native + + + native + + + + false + false + true + + + + diff --git a/apache-camel/camel-aws-s3-kafka/src/main/docker/Dockerfile.jvm b/apache-camel/camel-aws-s3-kafka/src/main/docker/Dockerfile.jvm new file mode 100644 index 0000000..545c95e --- /dev/null +++ b/apache-camel/camel-aws-s3-kafka/src/main/docker/Dockerfile.jvm @@ -0,0 +1,100 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode +# +# Before building the container image run: +# +# ./mvnw package +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.jvm -t quarkus/camel-aws-s3-kafka-jvm . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/camel-aws-s3-kafka-jvm +# +# If you want to include the debug port into your docker image +# you will have to expose the debug port (default 5005 being the default) like this : EXPOSE 8080 5005. +# Additionally you will have to set -e JAVA_DEBUG=true and -e JAVA_DEBUG_PORT=*:5005 +# when running the container +# +# Then run the container using : +# +# docker run -i --rm -p 8080:8080 quarkus/camel-aws-s3-kafka-jvm +# +# This image uses the `run-java.sh` script to run the application. +# This scripts computes the command line to execute your Java application, and +# includes memory/GC tuning. +# You can configure the behavior using the following environment properties: +# - JAVA_OPTS: JVM options passed to the `java` command (example: "-verbose:class") - Be aware that this will override +# the default JVM options, use `JAVA_OPTS_APPEND` to append options +# - JAVA_OPTS_APPEND: User specified Java options to be appended to generated options +# in JAVA_OPTS (example: "-Dsome.property=foo") +# - JAVA_MAX_MEM_RATIO: Is used when no `-Xmx` option is given in JAVA_OPTS. This is +# used to calculate a default maximal heap memory based on a containers restriction. +# If used in a container without any memory constraints for the container then this +# option has no effect. If there is a memory constraint then `-Xmx` is set to a ratio +# of the container available memory as set here. The default is `50` which means 50% +# of the available memory is used as an upper boundary. You can skip this mechanism by +# setting this value to `0` in which case no `-Xmx` option is added. +# - JAVA_INITIAL_MEM_RATIO: Is used when no `-Xms` option is given in JAVA_OPTS. This +# is used to calculate a default initial heap memory based on the maximum heap memory. +# If used in a container without any memory constraints for the container then this +# option has no effect. If there is a memory constraint then `-Xms` is set to a ratio +# of the `-Xmx` memory as set here. The default is `25` which means 25% of the `-Xmx` +# is used as the initial heap size. You can skip this mechanism by setting this value +# to `0` in which case no `-Xms` option is added (example: "25") +# - JAVA_MAX_INITIAL_MEM: Is used when no `-Xms` option is given in JAVA_OPTS. +# This is used to calculate the maximum value of the initial heap memory. If used in +# a container without any memory constraints for the container then this option has +# no effect. If there is a memory constraint then `-Xms` is limited to the value set +# here. The default is 4096MB which means the calculated value of `-Xms` never will +# be greater than 4096MB. The value of this variable is expressed in MB (example: "4096") +# - JAVA_DIAGNOSTICS: Set this to get some diagnostics information to standard output +# when things are happening. This option, if set to true, will set +# `-XX:+UnlockDiagnosticVMOptions`. Disabled by default (example: "true"). +# - JAVA_DEBUG: If set remote debugging will be switched on. Disabled by default (example: +# true"). +# - JAVA_DEBUG_PORT: Port used for remote debugging. Defaults to 5005 (example: "8787"). +# - CONTAINER_CORE_LIMIT: A calculated core limit as described in +# https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt. (example: "2") +# - CONTAINER_MAX_MEMORY: Memory limit given to the container (example: "1024"). +# - GC_MIN_HEAP_FREE_RATIO: Minimum percentage of heap free after GC to avoid expansion. +# (example: "20") +# - GC_MAX_HEAP_FREE_RATIO: Maximum percentage of heap free after GC to avoid shrinking. +# (example: "40") +# - GC_TIME_RATIO: Specifies the ratio of the time spent outside the garbage collection. +# (example: "4") +# - GC_ADAPTIVE_SIZE_POLICY_WEIGHT: The weighting given to the current GC time versus +# previous GC times. (example: "90") +# - GC_METASPACE_SIZE: The initial metaspace size. (example: "20") +# - GC_MAX_METASPACE_SIZE: The maximum metaspace size. (example: "100") +# - GC_CONTAINER_OPTIONS: Specify Java GC to use. The value of this variable should +# contain the necessary JRE command-line options to specify the required GC, which +# will override the default of `-XX:+UseParallelGC` (example: -XX:+UseG1GC). +# - HTTPS_PROXY: The location of the https proxy. (example: "myuser@127.0.0.1:8080") +# - HTTP_PROXY: The location of the http proxy. (example: "myuser@127.0.0.1:8080") +# - NO_PROXY: A comma separated lists of hosts, IP addresses or domains that can be +# accessed directly. (example: "foo.example.com,bar.example.com") +# +# You can find more information about the UBI base runtime images and their configuration here: +# https://rh-openjdk.github.io/redhat-openjdk-containers/ +### +FROM registry.access.redhat.com/ubi9/openjdk-21-runtime:1.24 + +ENV LANGUAGE='en_US:en' + + +# We make four distinct layers so if there are application changes the library layers can be re-used +COPY --chown=185 target/quarkus-app/lib/ /deployments/lib/ +COPY --chown=185 target/quarkus-app/*.jar /deployments/ +COPY --chown=185 target/quarkus-app/app/ /deployments/app/ +COPY --chown=185 target/quarkus-app/quarkus/ /deployments/quarkus/ + +EXPOSE 8080 +USER 185 +ENV JAVA_OPTS_APPEND="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" +ENV JAVA_APP_JAR="/deployments/quarkus-run.jar" + +ENTRYPOINT [ "/opt/jboss/container/java/run/run-java.sh" ] + diff --git a/apache-camel/camel-aws-s3-kafka/src/main/docker/Dockerfile.legacy-jar b/apache-camel/camel-aws-s3-kafka/src/main/docker/Dockerfile.legacy-jar new file mode 100644 index 0000000..13c2edd --- /dev/null +++ b/apache-camel/camel-aws-s3-kafka/src/main/docker/Dockerfile.legacy-jar @@ -0,0 +1,96 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode +# +# Before building the container image run: +# +# ./mvnw package -Dquarkus.package.jar.type=legacy-jar +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.legacy-jar -t quarkus/camel-aws-s3-kafka-legacy-jar . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/camel-aws-s3-kafka-legacy-jar +# +# If you want to include the debug port into your docker image +# you will have to expose the debug port (default 5005 being the default) like this : EXPOSE 8080 5005. +# Additionally you will have to set -e JAVA_DEBUG=true and -e JAVA_DEBUG_PORT=*:5005 +# when running the container +# +# Then run the container using : +# +# docker run -i --rm -p 8080:8080 quarkus/camel-aws-s3-kafka-legacy-jar +# +# This image uses the `run-java.sh` script to run the application. +# This scripts computes the command line to execute your Java application, and +# includes memory/GC tuning. +# You can configure the behavior using the following environment properties: +# - JAVA_OPTS: JVM options passed to the `java` command (example: "-verbose:class") - Be aware that this will override +# the default JVM options, use `JAVA_OPTS_APPEND` to append options +# - JAVA_OPTS_APPEND: User specified Java options to be appended to generated options +# in JAVA_OPTS (example: "-Dsome.property=foo") +# - JAVA_MAX_MEM_RATIO: Is used when no `-Xmx` option is given in JAVA_OPTS. This is +# used to calculate a default maximal heap memory based on a containers restriction. +# If used in a container without any memory constraints for the container then this +# option has no effect. If there is a memory constraint then `-Xmx` is set to a ratio +# of the container available memory as set here. The default is `50` which means 50% +# of the available memory is used as an upper boundary. You can skip this mechanism by +# setting this value to `0` in which case no `-Xmx` option is added. +# - JAVA_INITIAL_MEM_RATIO: Is used when no `-Xms` option is given in JAVA_OPTS. This +# is used to calculate a default initial heap memory based on the maximum heap memory. +# If used in a container without any memory constraints for the container then this +# option has no effect. If there is a memory constraint then `-Xms` is set to a ratio +# of the `-Xmx` memory as set here. The default is `25` which means 25% of the `-Xmx` +# is used as the initial heap size. You can skip this mechanism by setting this value +# to `0` in which case no `-Xms` option is added (example: "25") +# - JAVA_MAX_INITIAL_MEM: Is used when no `-Xms` option is given in JAVA_OPTS. +# This is used to calculate the maximum value of the initial heap memory. If used in +# a container without any memory constraints for the container then this option has +# no effect. If there is a memory constraint then `-Xms` is limited to the value set +# here. The default is 4096MB which means the calculated value of `-Xms` never will +# be greater than 4096MB. The value of this variable is expressed in MB (example: "4096") +# - JAVA_DIAGNOSTICS: Set this to get some diagnostics information to standard output +# when things are happening. This option, if set to true, will set +# `-XX:+UnlockDiagnosticVMOptions`. Disabled by default (example: "true"). +# - JAVA_DEBUG: If set remote debugging will be switched on. Disabled by default (example: +# true"). +# - JAVA_DEBUG_PORT: Port used for remote debugging. Defaults to 5005 (example: "8787"). +# - CONTAINER_CORE_LIMIT: A calculated core limit as described in +# https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt. (example: "2") +# - CONTAINER_MAX_MEMORY: Memory limit given to the container (example: "1024"). +# - GC_MIN_HEAP_FREE_RATIO: Minimum percentage of heap free after GC to avoid expansion. +# (example: "20") +# - GC_MAX_HEAP_FREE_RATIO: Maximum percentage of heap free after GC to avoid shrinking. +# (example: "40") +# - GC_TIME_RATIO: Specifies the ratio of the time spent outside the garbage collection. +# (example: "4") +# - GC_ADAPTIVE_SIZE_POLICY_WEIGHT: The weighting given to the current GC time versus +# previous GC times. (example: "90") +# - GC_METASPACE_SIZE: The initial metaspace size. (example: "20") +# - GC_MAX_METASPACE_SIZE: The maximum metaspace size. (example: "100") +# - GC_CONTAINER_OPTIONS: Specify Java GC to use. The value of this variable should +# contain the necessary JRE command-line options to specify the required GC, which +# will override the default of `-XX:+UseParallelGC` (example: -XX:+UseG1GC). +# - HTTPS_PROXY: The location of the https proxy. (example: "myuser@127.0.0.1:8080") +# - HTTP_PROXY: The location of the http proxy. (example: "myuser@127.0.0.1:8080") +# - NO_PROXY: A comma separated lists of hosts, IP addresses or domains that can be +# accessed directly. (example: "foo.example.com,bar.example.com") +# +# You can find more information about the UBI base runtime images and their configuration here: +# https://rh-openjdk.github.io/redhat-openjdk-containers/ +### +FROM registry.access.redhat.com/ubi9/openjdk-21-runtime:1.24 + +ENV LANGUAGE='en_US:en' + + +COPY target/lib/* /deployments/lib/ +COPY target/*-runner.jar /deployments/quarkus-run.jar + +EXPOSE 8080 +USER 185 +ENV JAVA_OPTS_APPEND="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" +ENV JAVA_APP_JAR="/deployments/quarkus-run.jar" + +ENTRYPOINT [ "/opt/jboss/container/java/run/run-java.sh" ] diff --git a/apache-camel/camel-aws-s3-kafka/src/main/docker/Dockerfile.native b/apache-camel/camel-aws-s3-kafka/src/main/docker/Dockerfile.native new file mode 100644 index 0000000..1879ab7 --- /dev/null +++ b/apache-camel/camel-aws-s3-kafka/src/main/docker/Dockerfile.native @@ -0,0 +1,29 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode. +# +# Before building the container image run: +# +# ./mvnw package -Dnative +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.native -t quarkus/camel-aws-s3-kafka . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/camel-aws-s3-kafka +# +# The ` registry.access.redhat.com/ubi9/ubi-minimal:9.7` base image is based on UBI 9. +# To use UBI 8, switch to `quay.io/ubi8/ubi-minimal:8.10`. +### +FROM registry.access.redhat.com/ubi9/ubi-minimal:9.7 +WORKDIR /work/ +RUN chown 1001 /work \ + && chmod "g+rwX" /work \ + && chown 1001:root /work +COPY --chown=1001:root --chmod=0755 target/*-runner /work/application + +EXPOSE 8080 +USER 1001 + +ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"] diff --git a/apache-camel/camel-aws-s3-kafka/src/main/docker/Dockerfile.native-micro b/apache-camel/camel-aws-s3-kafka/src/main/docker/Dockerfile.native-micro new file mode 100644 index 0000000..0ef30b7 --- /dev/null +++ b/apache-camel/camel-aws-s3-kafka/src/main/docker/Dockerfile.native-micro @@ -0,0 +1,32 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode. +# It uses a micro base image, tuned for Quarkus native executables. +# It reduces the size of the resulting container image. +# Check https://quarkus.io/guides/quarkus-runtime-base-image for further information about this image. +# +# Before building the container image run: +# +# ./mvnw package -Dnative +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.native-micro -t quarkus/camel-aws-s3-kafka . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/camel-aws-s3-kafka +# +# The `quay.io/quarkus/ubi9-quarkus-micro-image:2.0` base image is based on UBI 9. +# To use UBI 8, switch to `quay.io/quarkus/quarkus-micro-image:2.0`. +### +FROM quay.io/quarkus/ubi9-quarkus-micro-image:2.0 +WORKDIR /work/ +RUN chown 1001 /work \ + && chmod "g+rwX" /work \ + && chown 1001:root /work +COPY --chown=1001:root --chmod=0755 target/*-runner /work/application + +EXPOSE 8080 +USER 1001 + +ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"] diff --git a/apache-camel/camel-aws-s3-kafka/src/main/java/org/acme/Routes.java b/apache-camel/camel-aws-s3-kafka/src/main/java/org/acme/Routes.java new file mode 100644 index 0000000..04912b2 --- /dev/null +++ b/apache-camel/camel-aws-s3-kafka/src/main/java/org/acme/Routes.java @@ -0,0 +1,25 @@ +package org.acme; + +import org.apache.camel.builder.endpoint.EndpointRouteBuilder; + +public class Routes extends EndpointRouteBuilder { + + @Override + public void configure() throws Exception { + from("kamelet:aws-s3-source?" + + "bucketNameOrArn={{aws.s3.bucketNameOrArn}}&" + + "region={{aws.s3.region}}&" + + "overrideEndpoint=true&" + + "forcePathStyle=true&" + + "uriEndpointOverride={{aws.s3.uriEndpointOverride}}&" + + "accessKey={{aws.s3.accessKey}}&" + + "secretKey={{aws.s3.secretKey}}") + .split(body().tokenize("\n")) + .filter(simple("${body} != \"\"")) + .setBody() + .simple(""" + { "message": "${body}" } + """) + .to(kafka("s3-events")); + } +} diff --git a/apache-camel/camel-aws-s3-kafka/src/main/resources/application.properties b/apache-camel/camel-aws-s3-kafka/src/main/resources/application.properties new file mode 100644 index 0000000..d82e887 --- /dev/null +++ b/apache-camel/camel-aws-s3-kafka/src/main/resources/application.properties @@ -0,0 +1,9 @@ +# AWS S3 endpoint +aws.s3.bucketNameOrArn=citrus-camel-demo +aws.s3.region=us-east-1 +aws.s3.uriEndpointOverride=http://localhost:4566 +aws.s3.accessKey=accesskey +aws.s3.secretKey=secretkey + +# Kafka endpoint +kafka.bootstrap.servers=localhost:9092 diff --git a/apache-camel/camel-aws-s3-kafka/src/test/java/org/acme/QuarkusApplicationTest.java b/apache-camel/camel-aws-s3-kafka/src/test/java/org/acme/QuarkusApplicationTest.java new file mode 100644 index 0000000..1d4a6e2 --- /dev/null +++ b/apache-camel/camel-aws-s3-kafka/src/test/java/org/acme/QuarkusApplicationTest.java @@ -0,0 +1,137 @@ +package org.acme; + +import java.util.Collections; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ExecutionException; + +import io.quarkus.test.junit.QuarkusTest; +import org.apache.kafka.clients.admin.Admin; +import org.apache.kafka.clients.admin.AdminClientConfig; +import org.apache.kafka.clients.admin.CreateTopicsResult; +import org.apache.kafka.clients.admin.NewTopic; +import org.citrusframework.GherkinTestActionRunner; +import org.citrusframework.TestActionSupport; +import org.citrusframework.annotations.CitrusEndpoint; +import org.citrusframework.annotations.CitrusResource; +import org.citrusframework.exceptions.CitrusRuntimeException; +import org.citrusframework.kafka.config.annotation.KafkaEndpointConfig; +import org.citrusframework.kafka.endpoint.KafkaEndpoint; +import org.citrusframework.quarkus.CitrusSupport; +import org.citrusframework.actions.testcontainers.aws2.AwsService; +import org.citrusframework.testcontainers.aws2.LocalStackContainer; +import org.citrusframework.testcontainers.aws2.quarkus.LocalStackContainerSupport; +import org.citrusframework.testcontainers.kafka.quarkus.apache.KafkaContainerSupport; +import org.citrusframework.testcontainers.quarkus.ContainerLifecycleListener; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testcontainers.kafka.KafkaContainer; +import software.amazon.awssdk.services.s3.S3Client; + +@QuarkusTest +@CitrusSupport +@LocalStackContainerSupport(services = AwsService.S3, + containerLifecycleListener = QuarkusApplicationTest.LocalStackConfigurer.class) +@KafkaContainerSupport(port = 9092, version = "4.2.0", + containerLifecycleListener = QuarkusApplicationTest.KafkaConfigurer.class) +class QuarkusApplicationTest implements TestActionSupport { + + private static final Logger log = LoggerFactory.getLogger(QuarkusApplicationTest.class); + + private static final String BUCKET_NAME = "citrus-camel-demo"; + + @CitrusEndpoint + @KafkaEndpointConfig(topic = "s3-events") + KafkaEndpoint s3Events; + + @CitrusResource + GherkinTestActionRunner runner; + + @Test + void shouldSplitS3FileToKafkaEvents() { + runner.when( + camel() + .send() + .endpoint("aws2-s3://" + BUCKET_NAME + "?" + + "overrideEndpoint=true&" + + "forcePathStyle=true&" + + "uriEndpointOverride={{aws.s3.uriEndpointOverride}}&" + + "accessKey={{aws.s3.accessKey}}&" + + "secretKey={{aws.s3.secretKey}}&" + + "region={{aws.s3.region}}") + .message() + .fork(true) + .body("Hello Camel!\nHello Citrus!\nHello Quarkus!") + .header("CamelAwsS3Key", "hello.txt") + ); + + runner.then( + receive() + .endpoint(s3Events) + .message() + .body(""" + { "message": "Hello Camel!" } + """) + ); + + runner.then( + receive() + .endpoint(s3Events) + .message() + .body(""" + { "message": "Hello Citrus!" } + """) + ); + + runner.then( + receive() + .endpoint(s3Events) + .message() + .body(""" + { "message": "Hello Quarkus!" } + """) + ); + } + + public static class LocalStackConfigurer implements ContainerLifecycleListener { + @Override + public Map started(LocalStackContainer container) { + String serviceEndpoint = container.getServiceEndpoint().toString(); + log.info("LocalStack started at: {}", serviceEndpoint); + + S3Client s3Client = container.getClient(AwsService.S3); + s3Client.createBucket(builder -> builder.bucket(BUCKET_NAME)); + log.info("Successfully created S3 bucket: {}", BUCKET_NAME); + + return Map.of( + "aws.s3.bucketNameOrArn", BUCKET_NAME, + "aws.s3.uriEndpointOverride", serviceEndpoint, + "aws.s3.accessKey", container.getAccessKey(), + "aws.s3.secretKey", container.getSecretKey(), + "aws.s3.region", container.getRegion() + ); + } + } + + public static class KafkaConfigurer implements ContainerLifecycleListener { + @Override + public Map started(KafkaContainer container) { + try (Admin adminClient = Admin.create(Collections.singletonMap( + AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, container.getBootstrapServers()))) { + CreateTopicsResult result = adminClient.createTopics(Set.of( + new NewTopic("s3-events", 1, (short) 1) + )); + + result.all().get(); + + adminClient.listTopics().names().get() + .forEach(topic -> log.info("Successfully created topic: {}", topic)); + } catch (ExecutionException | InterruptedException e) { + throw new CitrusRuntimeException("Failed to create topics", e); + } + + return Collections.emptyMap(); + } + } +} diff --git a/apache-camel/camel-aws-s3-kafka/src/test/resources/application.properties b/apache-camel/camel-aws-s3-kafka/src/test/resources/application.properties new file mode 100644 index 0000000..1127822 --- /dev/null +++ b/apache-camel/camel-aws-s3-kafka/src/test/resources/application.properties @@ -0,0 +1 @@ +quarkus.arc.ignored-split-packages=org.citrusframework.* diff --git a/apache-camel/pom.xml b/apache-camel/pom.xml index 00231f4..4cbbaf3 100644 --- a/apache-camel/pom.xml +++ b/apache-camel/pom.xml @@ -9,6 +9,7 @@ pom + camel-aws-s3-kafka camel-cxf-soap camel-cxf-soap-client camel-direct