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 2023/12/13 08:44:07 UTC

(camel) branch CAMEL-20229 created (now 8712dd43173)

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

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


      at 8712dd43173 CAMEL-20229 - Camel-Azure-Storage-Queue: Add CloudEvents Data Type Transformer

This branch includes the following new commits:

     new 8712dd43173 CAMEL-20229 - Camel-Azure-Storage-Queue: Add CloudEvents Data Type 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-20229 - Camel-Azure-Storage-Queue: Add CloudEvents Data Type 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-20229
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 8712dd43173546abdb1bd7cd745a264291c3056d
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Dec 13 09:39:05 2023 +0100

    CAMEL-20229 - Camel-Azure-Storage-Queue: Add CloudEvents Data Type Transformer
    
    Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
 .../camel-azure/camel-azure-storage-queue/pom.xml  |  8 ++++
 .../azure-storage-queue-application-cloudevents    |  2 +
 ...eStorageQueueCloudEventDataTypeTransformer.java | 56 ++++++++++++++++++++++
 3 files changed, 66 insertions(+)

diff --git a/components/camel-azure/camel-azure-storage-queue/pom.xml b/components/camel-azure/camel-azure-storage-queue/pom.xml
index cd6269acaa6..72c13c3ad44 100644
--- a/components/camel-azure/camel-azure-storage-queue/pom.xml
+++ b/components/camel-azure/camel-azure-storage-queue/pom.xml
@@ -74,6 +74,14 @@
             <version>${commons-io-version}</version>
         </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-azure/camel-azure-storage-queue/src/generated/resources/META-INF/services/org/apache/camel/transformer/azure-storage-queue-application-cloudevents b/components/camel-azure/camel-azure-storage-queue/src/generated/resources/META-INF/services/org/apache/camel/transformer/azure-storage-queue-application-cloudevents
new file mode 100644
index 00000000000..a2548d1f412
--- /dev/null
+++ b/components/camel-azure/camel-azure-storage-queue/src/generated/resources/META-INF/services/org/apache/camel/transformer/azure-storage-queue-application-cloudevents
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.azure.storage.queue.transform.AzureStorageQueueCloudEventDataTypeTransformer
diff --git a/components/camel-azure/camel-azure-storage-queue/src/main/java/org/apache/camel/component/azure/storage/queue/transform/AzureStorageQueueCloudEventDataTypeTransformer.java b/components/camel-azure/camel-azure-storage-queue/src/main/java/org/apache/camel/component/azure/storage/queue/transform/AzureStorageQueueCloudEventDataTypeTransformer.java
new file mode 100644
index 00000000000..6bed53a066d
--- /dev/null
+++ b/components/camel-azure/camel-azure-storage-queue/src/main/java/org/apache/camel/component/azure/storage/queue/transform/AzureStorageQueueCloudEventDataTypeTransformer.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.azure.storage.queue.transform;
+
+import java.util.Map;
+
+import org.apache.camel.Message;
+import org.apache.camel.component.azure.storage.queue.QueueConstants;
+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;
+
+/**
+ * Output data type represents Azure Storage Queue receive messages operation as CloudEvent V1. The data type sets Camel
+ * specific CloudEvent headers on the exchange.
+ */
+@DataTypeTransformer(name = "azure-storage-queue:application-cloudevents")
+public class AzureStorageQueueCloudEventDataTypeTransformer 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(CloudEvents.CAMEL_CLOUD_EVENT_ID, message.getExchange().getExchangeId());
+        headers.putIfAbsent(CloudEvent.CAMEL_CLOUD_EVENT_VERSION, cloudEvent.version());
+        headers.put(CloudEvents.CAMEL_CLOUD_EVENT_TYPE, "org.apache.camel.event.azure.storage.queue.receiveMessages");
+
+        if (message.getHeaders().containsKey(QueueConstants.MESSAGE_ID)) {
+            headers.put(CloudEvents.CAMEL_CLOUD_EVENT_SOURCE,
+                    "azure.storage.blob." + message.getHeader(QueueConstants.MESSAGE_ID, String.class));
+        }
+
+        if (message.getHeaders().containsKey(QueueConstants.POP_RECEIPT)) {
+            headers.put(CloudEvents.CAMEL_CLOUD_EVENT_SUBJECT, message.getHeader(QueueConstants.POP_RECEIPT, String.class));
+        }
+        headers.put(CloudEvents.CAMEL_CLOUD_EVENT_TIME, cloudEvent.getEventTime(message.getExchange()));
+    }
+}