You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2024/02/16 12:56:59 UTC

(camel) branch CAMEL-20416 created (now bb560d27734)

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

acosentino pushed a change to branch CAMEL-20416
in repository https://gitbox.apache.org/repos/asf/camel.git


      at bb560d27734 CAMEL-20416 - AWS Kinesis CloudEvent Transformer

This branch includes the following new commits:

     new bb560d27734 CAMEL-20416 - AWS Kinesis CloudEvent Transformer

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(camel) 01/01: CAMEL-20416 - AWS Kinesis CloudEvent Transformer

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch CAMEL-20416
in repository https://gitbox.apache.org/repos/asf/camel.git

commit bb560d277349a6816d858cbf6802bc4d6c1d8491
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Fri Feb 16 13:56:08 2024 +0100

    CAMEL-20416 - AWS Kinesis CloudEvent Transformer
    
    Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
 .../apache/camel/catalog/transformers.properties   |  1 +
 .../aws2-kinesis-application-cloudevents.json      | 14 ++++++
 components/camel-aws/camel-aws2-kinesis/pom.xml    |  8 ++++
 .../org/apache/camel/transformer.properties        |  7 +++
 .../aws2-kinesis-application-cloudevents           |  2 +
 .../aws2-kinesis-application-cloudevents.json      | 14 ++++++
 .../KinesisCloudEventDataTypeTransformer.java      | 56 ++++++++++++++++++++++
 7 files changed, 102 insertions(+)

diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers.properties b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers.properties
index 371ae705b6e..67d1f0b7960 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers.properties
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers.properties
@@ -8,6 +8,7 @@ avro-x-java-object
 avro-x-struct
 aws-cloudtrail-application-cloudevents
 aws2-ddb-application-json
+aws2-kinesis-application-cloudevents
 aws2-s3-application-cloudevents
 aws2-sqs-application-cloudevents
 azure-storage-blob-application-cloudevents
diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers/aws2-kinesis-application-cloudevents.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers/aws2-kinesis-application-cloudevents.json
new file mode 100644
index 00000000000..acb5b185ee2
--- /dev/null
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers/aws2-kinesis-application-cloudevents.json
@@ -0,0 +1,14 @@
+{
+  "transformer": {
+    "kind": "transformer",
+    "name": "aws2-kinesis:application-cloudevents",
+    "title": "Aws2 Kinesis (Application Cloudevents)",
+    "description": "Adds CloudEvent headers to the Camel message with AWS Kinesis get records response details",
+    "deprecated": false,
+    "javaType": "org.apache.camel.component.aws2.kinesis.transform.KinesisCloudEventDataTypeTransformer",
+    "groupId": "org.apache.camel",
+    "artifactId": "camel-aws2-kinesis",
+    "version": "4.4.0-SNAPSHOT"
+  }
+}
+
diff --git a/components/camel-aws/camel-aws2-kinesis/pom.xml b/components/camel-aws/camel-aws2-kinesis/pom.xml
index f58dd9b86aa..30c0c9a6691 100644
--- a/components/camel-aws/camel-aws2-kinesis/pom.xml
+++ b/components/camel-aws/camel-aws2-kinesis/pom.xml
@@ -62,6 +62,14 @@
             <artifactId>camel-health</artifactId>
         </dependency>
 
+        <!-- optional CloudEvent support -->
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-cloudevents</artifactId>
+            <scope>provided</scope>
+            <optional>true</optional>
+        </dependency>
+
         <!-- for testing -->
         <dependency>
             <groupId>org.apache.camel</groupId>
diff --git a/components/camel-aws/camel-aws2-kinesis/src/generated/resources/META-INF/services/org/apache/camel/transformer.properties b/components/camel-aws/camel-aws2-kinesis/src/generated/resources/META-INF/services/org/apache/camel/transformer.properties
new file mode 100644
index 00000000000..1f0f10950f5
--- /dev/null
+++ b/components/camel-aws/camel-aws2-kinesis/src/generated/resources/META-INF/services/org/apache/camel/transformer.properties
@@ -0,0 +1,7 @@
+# Generated by camel build tools - do NOT edit this file!
+transformers=aws2-kinesis:application-cloudevents
+groupId=org.apache.camel
+artifactId=camel-aws2-kinesis
+version=4.4.0-SNAPSHOT
+projectName=Camel :: AWS2 Kinesis
+projectDescription=Consuming and Producing data to AWS Kinesis Service
diff --git a/components/camel-aws/camel-aws2-kinesis/src/generated/resources/META-INF/services/org/apache/camel/transformer/aws2-kinesis-application-cloudevents b/components/camel-aws/camel-aws2-kinesis/src/generated/resources/META-INF/services/org/apache/camel/transformer/aws2-kinesis-application-cloudevents
new file mode 100644
index 00000000000..f0c0338d0b7
--- /dev/null
+++ b/components/camel-aws/camel-aws2-kinesis/src/generated/resources/META-INF/services/org/apache/camel/transformer/aws2-kinesis-application-cloudevents
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.aws2.kinesis.transform.KinesisCloudEventDataTypeTransformer
diff --git a/components/camel-aws/camel-aws2-kinesis/src/generated/resources/META-INF/services/org/apache/camel/transformer/aws2-kinesis-application-cloudevents.json b/components/camel-aws/camel-aws2-kinesis/src/generated/resources/META-INF/services/org/apache/camel/transformer/aws2-kinesis-application-cloudevents.json
new file mode 100644
index 00000000000..acb5b185ee2
--- /dev/null
+++ b/components/camel-aws/camel-aws2-kinesis/src/generated/resources/META-INF/services/org/apache/camel/transformer/aws2-kinesis-application-cloudevents.json
@@ -0,0 +1,14 @@
+{
+  "transformer": {
+    "kind": "transformer",
+    "name": "aws2-kinesis:application-cloudevents",
+    "title": "Aws2 Kinesis (Application Cloudevents)",
+    "description": "Adds CloudEvent headers to the Camel message with AWS Kinesis get records response details",
+    "deprecated": false,
+    "javaType": "org.apache.camel.component.aws2.kinesis.transform.KinesisCloudEventDataTypeTransformer",
+    "groupId": "org.apache.camel",
+    "artifactId": "camel-aws2-kinesis",
+    "version": "4.4.0-SNAPSHOT"
+  }
+}
+
diff --git a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/transform/KinesisCloudEventDataTypeTransformer.java b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/transform/KinesisCloudEventDataTypeTransformer.java
new file mode 100644
index 00000000000..4d237b2a38e
--- /dev/null
+++ b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/transform/KinesisCloudEventDataTypeTransformer.java
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ */
+
+package org.apache.camel.component.aws2.kinesis.transform;
+
+import org.apache.camel.Message;
+import org.apache.camel.component.aws2.kinesis.Kinesis2Constants;
+import org.apache.camel.component.cloudevents.CloudEvent;
+import org.apache.camel.component.cloudevents.CloudEvents;
+import org.apache.camel.spi.DataType;
+import org.apache.camel.spi.DataTypeTransformer;
+import org.apache.camel.spi.Transformer;
+
+import java.util.Map;
+
+/**
+ * Data type transformer converts AWS Kinesis get records response to CloudEvent v1_0 data format. The data type sets Camel
+ * specific CloudEvent headers with values extracted from AWS Kinesis get object response.
+ */
+@DataTypeTransformer(name = "aws2-kinesis:application-cloudevents",
+                     description = "Adds CloudEvent headers to the Camel message with AWS Kinesis get records response details")
+public class KinesisCloudEventDataTypeTransformer extends Transformer {
+
+    @Override
+    public void transform(Message message, DataType fromType, DataType toType) {
+        final Map<String, Object> headers = message.getHeaders();
+
+        CloudEvent cloudEvent = CloudEvents.v1_0;
+        headers.putIfAbsent(CloudEvent.CAMEL_CLOUD_EVENT_ID, message.getExchange().getExchangeId());
+        headers.putIfAbsent(CloudEvent.CAMEL_CLOUD_EVENT_VERSION, cloudEvent.version());
+        headers.put(CloudEvent.CAMEL_CLOUD_EVENT_TYPE, "org.apache.camel.event.aws.kinesis.getRecords");
+
+        if (message.getHeaders().containsKey(Kinesis2Constants.PARTITION_KEY)) {
+            headers.put(CloudEvent.CAMEL_CLOUD_EVENT_SOURCE,
+                    "aws.kinesis.partition.key." + message.getHeader(Kinesis2Constants.PARTITION_KEY, String.class));
+        }
+
+        headers.put(CloudEvent.CAMEL_CLOUD_EVENT_SUBJECT, message.getHeader(Kinesis2Constants.SHARD_ID, String.class));
+        headers.put(CloudEvent.CAMEL_CLOUD_EVENT_TIME, cloudEvent.getEventTime(message.getExchange()));
+        headers.put(CloudEvent.CAMEL_CLOUD_EVENT_CONTENT_TYPE, CloudEvent.APPLICATION_OCTET_STREAM_MIME_TYPE);
+    }
+}