You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by cd...@apache.org on 2025/01/30 10:44:30 UTC

(camel-jbang-examples) branch main updated: Add AWS SQS sink example

This is an automated email from the ASF dual-hosted git repository.

cdeppisch pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-jbang-examples.git


The following commit(s) were added to refs/heads/main by this push:
     new 2534c0a  Add AWS SQS sink example
2534c0a is described below

commit 2534c0a1243655229b8b441b12c88423e8c9841c
Author: Christoph Deppisch <cd...@redhat.com>
AuthorDate: Thu Jan 30 11:17:19 2025 +0100

    Add AWS SQS sink example
---
 .github/workflows/build.yml                        | 16 ++--
 .../aws-s3-event-based}/README.adoc                |  4 +-
 .../aws-s3-event-based}/application.properties     |  0
 .../aws-s3-event-based}/aws-s3-cdc-log.camel.yaml  |  0
 .../aws-s3-event-based}/example-file.txt           |  0
 .../aws-s3-event-based}/policy-queue.json          |  0
 .../aws-s3-event-based}/terraform/main.tf          |  0
 .../aws-s3-event-based}/test/amazonS3Client.groovy |  0
 .../test/application.test.properties               |  0
 .../test/aws-s3-cdc-log.camel.it.yaml              |  0
 .../aws-s3-event-based}/test/jbang.properties      |  2 +
 aws/aws-sqs/README.adoc                            | 93 ++++++++++++++++++++++
 .../aws-sqs}/application.properties                |  2 +-
 .../aws-sqs/http-to-aws-sqs.camel.yaml             | 19 ++---
 aws/aws-sqs/test/amazonSQSClient.groovy            | 36 +++++++++
 .../aws-sqs}/test/application.test.properties      | 11 +--
 aws/aws-sqs/test/http-to-aws-sqs.camel.it.yaml     | 46 +++++++++++
 .../aws-sqs}/test/jbang.properties                 |  5 +-
 ftp/test/jbang.properties                          |  2 +
 mqtt/test/jbang.properties                         |  2 +
 openapi/client/test/jbang.properties               |  2 +
 openapi/server/test/jbang.properties               |  2 +
 22 files changed, 210 insertions(+), 32 deletions(-)

diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 6fbb852..53c2519 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -50,9 +50,9 @@ jobs:
           curl -s "https://get.sdkman.io" | bash 
           source "/home/runner/.sdkman/bin/sdkman-init.sh"
           sdk install jbang
-          
+
           jbang --version
-          
+
           jbang trust add https://github.com/citrusframework/citrus/
           jbang trust add https://github.com/apache/camel/
 
@@ -68,18 +68,22 @@ jobs:
           pushd mqtt/test
           jbang citrus@citrusframework/citrus run mqtt.camel.it.yaml
           popd
-          
+
           pushd openapi/server/test
           jbang citrus@citrusframework/citrus run petstore.camel.it.yaml
           popd
-          
+
           pushd openapi/client/test
           jbang citrus@citrusframework/citrus run petstore-client.camel.it.yaml
           popd
-          
-          pushd aws-s3-event-based/test
+
+          pushd aws/aws-s3-event-based/test
           jbang citrus@citrusframework/citrus run aws-s3-cdc-log.camel.it.yaml
           popd
+
+          pushd aws/aws-sqs/test
+          jbang citrus@citrusframework/citrus run http-to-aws-sqs.camel.it.yaml
+          popd
       - uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
         if: always()
         with:
diff --git a/aws-s3-event-based/README.adoc b/aws/aws-s3-event-based/README.adoc
similarity index 99%
rename from aws-s3-event-based/README.adoc
rename to aws/aws-s3-event-based/README.adoc
index de4ecd6..9a35db3 100644
--- a/aws-s3-event-based/README.adoc
+++ b/aws/aws-s3-event-based/README.adoc
@@ -6,7 +6,7 @@ Through the usage of EventBridge and SQS Services you'll be able to consume even
 
 == Install Camel JBang
 
-include::../install.adoc[see installation]
+include::../../install.adoc[see installation]
 
 == Setup the AWS S3 bucket, SQS Queue and EventBridge Rule
 
@@ -108,7 +108,7 @@ You can enable the developer console via `--console` flag as show:
 $ camel run application.properties aws-s3-cdc-log.camel.yaml --console
 ----
 
-Then you can browse: http://localhost:8080/q/dev to introspect the running Camel Application.
+Then you can browse: http://localhost:8080/q/dev to introspect the running Camel application.
 
 == Create and delete an object
 
diff --git a/aws-s3-event-based/application.properties b/aws/aws-s3-event-based/application.properties
similarity index 100%
copy from aws-s3-event-based/application.properties
copy to aws/aws-s3-event-based/application.properties
diff --git a/aws-s3-event-based/aws-s3-cdc-log.camel.yaml b/aws/aws-s3-event-based/aws-s3-cdc-log.camel.yaml
similarity index 100%
copy from aws-s3-event-based/aws-s3-cdc-log.camel.yaml
copy to aws/aws-s3-event-based/aws-s3-cdc-log.camel.yaml
diff --git a/aws-s3-event-based/example-file.txt b/aws/aws-s3-event-based/example-file.txt
similarity index 100%
rename from aws-s3-event-based/example-file.txt
rename to aws/aws-s3-event-based/example-file.txt
diff --git a/aws-s3-event-based/policy-queue.json b/aws/aws-s3-event-based/policy-queue.json
similarity index 100%
rename from aws-s3-event-based/policy-queue.json
rename to aws/aws-s3-event-based/policy-queue.json
diff --git a/aws-s3-event-based/terraform/main.tf b/aws/aws-s3-event-based/terraform/main.tf
similarity index 100%
rename from aws-s3-event-based/terraform/main.tf
rename to aws/aws-s3-event-based/terraform/main.tf
diff --git a/aws-s3-event-based/test/amazonS3Client.groovy b/aws/aws-s3-event-based/test/amazonS3Client.groovy
similarity index 100%
rename from aws-s3-event-based/test/amazonS3Client.groovy
rename to aws/aws-s3-event-based/test/amazonS3Client.groovy
diff --git a/aws-s3-event-based/test/application.test.properties b/aws/aws-s3-event-based/test/application.test.properties
similarity index 100%
copy from aws-s3-event-based/test/application.test.properties
copy to aws/aws-s3-event-based/test/application.test.properties
diff --git a/aws-s3-event-based/test/aws-s3-cdc-log.camel.it.yaml b/aws/aws-s3-event-based/test/aws-s3-cdc-log.camel.it.yaml
similarity index 100%
rename from aws-s3-event-based/test/aws-s3-cdc-log.camel.it.yaml
rename to aws/aws-s3-event-based/test/aws-s3-cdc-log.camel.it.yaml
diff --git a/aws-s3-event-based/test/jbang.properties b/aws/aws-s3-event-based/test/jbang.properties
similarity index 77%
copy from aws-s3-event-based/test/jbang.properties
copy to aws/aws-s3-event-based/test/jbang.properties
index 673f58d..ccf0d7c 100644
--- a/aws-s3-event-based/test/jbang.properties
+++ b/aws/aws-s3-event-based/test/jbang.properties
@@ -6,3 +6,5 @@ org.apache.camel:camel-aws2-s3:4.9.0,\
 org.apache.camel:camel-aws2-sqs:4.9.0,\
 org.apache.camel:camel-aws2-eventbridge:4.9.0,\
 software.amazon.awssdk:sdk-core:2.30.2
+# Enable dump of Camel JBang integration output
+run.D=citrus.camel.jbang.dump.integration.output=true
diff --git a/aws/aws-sqs/README.adoc b/aws/aws-sqs/README.adoc
new file mode 100644
index 0000000..555f094
--- /dev/null
+++ b/aws/aws-sqs/README.adoc
@@ -0,0 +1,93 @@
+= AWS SQS sink
+
+In this sample you'll use the AWS SQS Sink Kamelet.
+The Camel integration exposes a Http service and for each incoming request the message body data is pushed to an AWS SQS queue.
+
+== Install Camel JBang
+
+include::../../install.adoc[see installation]
+
+== Setup the AWS SQS Queue
+
+You'll need a fully working AWS CLI locally.
+
+Create an SQS Queue where message data is pushed to
+
+[source,shell]
+----
+aws sqs create-queue --queue-name sqs-news --region eu-west-1
+----
+
+Don't forget to specify the correct sqs queue name in the `application.properties` file and adding correct credentials for AWS.
+
+== How to run
+
+Then you can run this example using:
+
+[source,shell]
+----
+$ camel run application.properties http-to-aws-sqs.camel.yaml
+----
+
+Or run it even shorter:
+
+[source,shell]
+----
+$ camel run *
+----
+
+== Developer Web Console
+
+You can enable the developer console via `--console` flag as show:
+
+[source,shell]
+----
+$ camel run application.properties http-to-aws-sqs.camel.yaml --console
+----
+
+Then you can browse: http://localhost:8080/q/dev to introspect the running Camel application.
+
+== Create requests and push data to SQS
+
+While the integration is running you can run the following commands:
+
+[source,shell]
+----
+curl -H "Content-Type: text/plain" -d 'Camel rocks!' http://localhost:8080/news
+----
+
+You will see the message content being processed and the AWS SQS queue should receive a new message with the respective content.
+
+== Integration testing
+
+The example provides an automated integration test (`http-to-aws-sqs.camel.it.yaml`) that you can run with the https://citrusframework.org/[Citrus] test framework.
+Please make sure to install Citrus as a JBang application (see link:../../install-citrus.adoc[Citrus installation guide]).
+
+Navigate to the test folder.
+
+[source,shell]
+----
+cd test/
+----
+
+You can run the test with:
+
+[source,shell]
+----
+citrus run http-to-aws-sqs.camel.it.yaml
+----
+
+The test prepares the complete infrastructure and starts the Camel route automatically via JBang.
+The Citrus test starts a Localstack Testcontainers instance to simulate the AWS SQS services.
+Once the AWS services are configured the test loads the Camel route and creates a proper Http POST request.
+As a result you will see the SQS data being consumed by the test to verify the event processing.
+
+== Help and contributions
+
+If you hit any problem using Camel or have some feedback, then please
+https://camel.apache.org/community/support/[let us know].
+
+We also love contributors, so
+https://camel.apache.org/community/contributing/[get involved] :-)
+
+The Camel riders!
diff --git a/aws-s3-event-based/application.properties b/aws/aws-sqs/application.properties
similarity index 95%
rename from aws-s3-event-based/application.properties
rename to aws/aws-sqs/application.properties
index 0797a10..62e8763 100644
--- a/aws-s3-event-based/application.properties
+++ b/aws/aws-sqs/application.properties
@@ -15,7 +15,7 @@
 # limitations under the License.
 #
 
-aws.queueNameOrArn=sqs-eventbridge-test-123
+aws.queueNameOrArn=sqs-news
 aws.secretKey=<secret_key>
 aws.accessKey=<access_key>
 aws.region=eu-west-1
diff --git a/aws-s3-event-based/aws-s3-cdc-log.camel.yaml b/aws/aws-sqs/http-to-aws-sqs.camel.yaml
similarity index 70%
rename from aws-s3-event-based/aws-s3-cdc-log.camel.yaml
rename to aws/aws-sqs/http-to-aws-sqs.camel.yaml
index e7605f4..d3d1b87 100644
--- a/aws-s3-event-based/aws-s3-cdc-log.camel.yaml
+++ b/aws/aws-sqs/http-to-aws-sqs.camel.yaml
@@ -17,17 +17,14 @@
 
 - route:
     from:
-      uri: "kamelet:aws-s3-event-based-source"
-      parameters:
-        queueNameOrArn: "{{aws.queueNameOrArn}}"
-        accessKey: "{{aws.accessKey}}"
-        secretKey: "{{aws.secretKey}}"
-        region: "{{aws.region}}"
-        overrideEndpoint: "{{aws.overrideEndpoint:false}}"
-        uriEndpointOverride: "{{aws.uriEndpointOverride:none}}"
-        getObject: true
+      uri: "platform-http:/news?httpMethodRestrict=POST"
       steps:
       - to:
-          uri: "kamelet:log-sink"
+          uri: "kamelet:aws-sqs-sink"
           parameters:
-            showStreams: true
+            queueNameOrArn: "{{aws.queueNameOrArn}}"
+            accessKey: "{{aws.accessKey}}"
+            secretKey: "{{aws.secretKey}}"
+            region: "{{aws.region}}"
+            overrideEndpoint: "{{aws.overrideEndpoint:false}}"
+            uriEndpointOverride: "{{aws.uriEndpointOverride:none}}"
diff --git a/aws/aws-sqs/test/amazonSQSClient.groovy b/aws/aws-sqs/test/amazonSQSClient.groovy
new file mode 100644
index 0000000..80676fa
--- /dev/null
+++ b/aws/aws-sqs/test/amazonSQSClient.groovy
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+
+import software.amazon.awssdk.auth.credentials.AwsBasicCredentials
+import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider
+import software.amazon.awssdk.regions.Region
+import software.amazon.awssdk.services.sqs.SqsClient
+
+SqsClient sqsClient = SqsClient
+        .builder()
+        .endpointOverride(URI.create('${CITRUS_TESTCONTAINERS_LOCALSTACK_SERVICE_URL}'))
+        .credentialsProvider(StaticCredentialsProvider.create(
+                AwsBasicCredentials.create(
+                        '${CITRUS_TESTCONTAINERS_LOCALSTACK_ACCESS_KEY}',
+                        '${CITRUS_TESTCONTAINERS_LOCALSTACK_SECRET_KEY}')
+        ))
+        .region(Region.of('${CITRUS_TESTCONTAINERS_LOCALSTACK_REGION}'))
+        .build()
+
+sqsClient.createQueue(s -> s.queueName('${aws.sqs.queueName}'))
+
+return sqsClient
diff --git a/aws-s3-event-based/test/application.test.properties b/aws/aws-sqs/test/application.test.properties
similarity index 73%
rename from aws-s3-event-based/test/application.test.properties
rename to aws/aws-sqs/test/application.test.properties
index 80170ba..eb02e13 100644
--- a/aws-s3-event-based/test/application.test.properties
+++ b/aws/aws-sqs/test/application.test.properties
@@ -15,16 +15,9 @@
 # limitations under the License.
 #
 
-aws.queueNameOrArn=${aws.queueNameOrArn}
+aws.queueNameOrArn=${aws.sqs.queueName}
 aws.secretKey=${CITRUS_TESTCONTAINERS_LOCALSTACK_SECRET_KEY}
 aws.accessKey=${CITRUS_TESTCONTAINERS_LOCALSTACK_ACCESS_KEY}
 aws.region=${CITRUS_TESTCONTAINERS_LOCALSTACK_REGION}
 aws.overrideEndpoint=true
-aws.uriEndpointOverride=${CITRUS_TESTCONTAINERS_LOCALSTACK_S3_URL}
-
-# AWS S3 component
-aws.bucketNameOrArn=${aws.bucketNameOrArn}
-camel.component.aws2-s3.forcePathStyle=true
-camel.component.aws2-s3.overrideEndpoint=true
-camel.component.aws2-s3.uriEndpointOverride=${CITRUS_TESTCONTAINERS_LOCALSTACK_S3_URL}
-
+aws.uriEndpointOverride=${CITRUS_TESTCONTAINERS_LOCALSTACK_SERVICE_URL}
diff --git a/aws/aws-sqs/test/http-to-aws-sqs.camel.it.yaml b/aws/aws-sqs/test/http-to-aws-sqs.camel.it.yaml
new file mode 100644
index 0000000..da2ed72
--- /dev/null
+++ b/aws/aws-sqs/test/http-to-aws-sqs.camel.it.yaml
@@ -0,0 +1,46 @@
+name: http-to-aws-sqs
+description: Sample test in YAML
+variables:
+  - name: "aws.sqs.queueName"
+    value: sqs-news
+  - name: "news.message"
+    value: "Camel rocks!"
+actions:
+  - testcontainers:
+      start:
+        localstack:
+          services:
+            - "SQS"
+  - camel:
+      startContext: { }
+  - camel:
+      createComponent:
+        name: amazonSQSClient
+        file: amazonSQSClient.groovy
+  - camel:
+      jbang:
+        run:
+          integration:
+            name: "http-to-aws-sqs"
+            file: "../http-to-aws-sqs.camel.yaml"
+            systemProperties:
+              file: "application.test.properties"
+  - http:
+      client: "http://localhost:8080"
+      sendRequest:
+        POST:
+          path: "/news"
+          contentType: "text/plain; charset=UTF-8"
+          body:
+            data: "${news.message}"
+  - http:
+      client: "http://localhost:8080"
+      receiveResponse:
+        response:
+          status: 200
+  - receive:
+      endpoint: |
+        camel:aws2-sqs:${aws.sqs.queueName}?amazonSQSClient=#amazonSQSClient
+      message:
+        body:
+          data: "${news.message}"
diff --git a/aws-s3-event-based/test/jbang.properties b/aws/aws-sqs/test/jbang.properties
similarity index 63%
rename from aws-s3-event-based/test/jbang.properties
rename to aws/aws-sqs/test/jbang.properties
index 673f58d..a6b8ca1 100644
--- a/aws-s3-event-based/test/jbang.properties
+++ b/aws/aws-sqs/test/jbang.properties
@@ -1,8 +1,7 @@
 # Declare required additional dependencies
 run.deps=org.citrusframework:citrus-camel:4.5.2,\
 org.citrusframework:citrus-testcontainers:4.5.2,\
-org.apache.camel:camel-endpointdsl:4.9.0,\
-org.apache.camel:camel-aws2-s3:4.9.0,\
 org.apache.camel:camel-aws2-sqs:4.9.0,\
-org.apache.camel:camel-aws2-eventbridge:4.9.0,\
 software.amazon.awssdk:sdk-core:2.30.2
+# Enable dump of Camel JBang integration output
+run.D=citrus.camel.jbang.dump.integration.output=true
diff --git a/ftp/test/jbang.properties b/ftp/test/jbang.properties
index 91e0ba3..b2bd4f2 100644
--- a/ftp/test/jbang.properties
+++ b/ftp/test/jbang.properties
@@ -5,3 +5,5 @@ org.citrusframework:citrus-jms:4.5.2,\
 org.apache.activemq:artemis-jakarta-client:2.37.0,\
 jakarta.inject:jakarta.inject-api:2.0.1,\
 jakarta.enterprise:jakarta.enterprise.cdi-api:4.1.0
+# Enable dump of Camel JBang integration output
+run.D=citrus.camel.jbang.dump.integration.output=true
diff --git a/mqtt/test/jbang.properties b/mqtt/test/jbang.properties
index 916a5ae..f529574 100644
--- a/mqtt/test/jbang.properties
+++ b/mqtt/test/jbang.properties
@@ -2,3 +2,5 @@
 run.deps=org.citrusframework:citrus-camel:4.5.2,\
 org.citrusframework:citrus-testcontainers:4.5.2,\
 org.apache.camel:camel-paho-mqtt5:4.9.0
+# Enable dump of Camel JBang integration output
+run.D=citrus.camel.jbang.dump.integration.output=true
diff --git a/openapi/client/test/jbang.properties b/openapi/client/test/jbang.properties
index 43f1b15..29e69ab 100644
--- a/openapi/client/test/jbang.properties
+++ b/openapi/client/test/jbang.properties
@@ -1,3 +1,5 @@
 # Declare required additional dependencies
 run.deps=org.citrusframework:citrus-camel:4.5.2,\
 org.citrusframework:citrus-openapi:4.5.2
+# Enable dump of Camel JBang integration output
+run.D=citrus.camel.jbang.dump.integration.output=true
diff --git a/openapi/server/test/jbang.properties b/openapi/server/test/jbang.properties
index 43f1b15..29e69ab 100644
--- a/openapi/server/test/jbang.properties
+++ b/openapi/server/test/jbang.properties
@@ -1,3 +1,5 @@
 # Declare required additional dependencies
 run.deps=org.citrusframework:citrus-camel:4.5.2,\
 org.citrusframework:citrus-openapi:4.5.2
+# Enable dump of Camel JBang integration output
+run.D=citrus.camel.jbang.dump.integration.output=true