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/22 14:15:02 UTC
(camel) branch CAMEL-20450 created (now 8b43a644ea8)
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a change to branch CAMEL-20450
in repository https://gitbox.apache.org/repos/asf/camel.git
at 8b43a644ea8 CAMEL-20450 - Azure Servicebus CloudEvent transformer
This branch includes the following new commits:
new 8b43a644ea8 CAMEL-20450 - Azure Servicebus 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-20450 - Azure Servicebus 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-20450
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 8b43a644ea845e0a95558a8032a175b42511b175
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Feb 22 15:14:19 2024 +0100
CAMEL-20450 - Azure Servicebus CloudEvent transformer
Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
.../apache/camel/catalog/transformers.properties | 1 +
.../azure-servicebus-application-cloudevents.json | 14 +++++
.../camel-azure/camel-azure-servicebus/pom.xml | 8 +++
.../org/apache/camel/transformer.properties | 7 +++
.../azure-servicebus-application-cloudevents | 2 +
.../azure-servicebus-application-cloudevents.json | 14 +++++
.../ServicebusCloudEventDataTypeTransformer.java | 60 ++++++++++++++++++++++
7 files changed, 106 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 b13e62c39b8..2a73fbbe310 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
@@ -13,6 +13,7 @@ aws2-kinesis-application-cloudevents
aws2-s3-application-cloudevents
aws2-sqs-application-cloudevents
azure-files-application-cloudevents
+azure-servicebus-application-cloudevents
azure-storage-blob-application-cloudevents
azure-storage-queue-application-cloudevents
google-sheets-application-x-struct
diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers/azure-servicebus-application-cloudevents.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers/azure-servicebus-application-cloudevents.json
new file mode 100644
index 00000000000..787aef0b8b2
--- /dev/null
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers/azure-servicebus-application-cloudevents.json
@@ -0,0 +1,14 @@
+{
+ "transformer": {
+ "kind": "transformer",
+ "name": "azure-servicebus:application-cloudevents",
+ "title": "Azure Servicebus (Application Cloudevents)",
+ "description": "Adds CloudEvent headers to the Camel message with Azure Service bus receive messages response details",
+ "deprecated": false,
+ "javaType": "org.apache.camel.component.azure.servicebus.transform.ServicebusCloudEventDataTypeTransformer",
+ "groupId": "org.apache.camel",
+ "artifactId": "camel-azure-servicebus",
+ "version": "4.5.0-SNAPSHOT"
+ }
+}
+
diff --git a/components/camel-azure/camel-azure-servicebus/pom.xml b/components/camel-azure/camel-azure-servicebus/pom.xml
index e30f778c774..88e41498786 100644
--- a/components/camel-azure/camel-azure-servicebus/pom.xml
+++ b/components/camel-azure/camel-azure-servicebus/pom.xml
@@ -51,6 +51,14 @@
<artifactId>azure-identity</artifactId>
</dependency>
+ <!-- optional CloudEvent support -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-cloudevents</artifactId>
+ <scope>provided</scope>
+ <optional>true</optional>
+ </dependency>
+
<!-- extras -->
<dependency>
<groupId>commons-io</groupId>
diff --git a/components/camel-azure/camel-azure-servicebus/src/generated/resources/META-INF/services/org/apache/camel/transformer.properties b/components/camel-azure/camel-azure-servicebus/src/generated/resources/META-INF/services/org/apache/camel/transformer.properties
new file mode 100644
index 00000000000..bf1b7894bcb
--- /dev/null
+++ b/components/camel-azure/camel-azure-servicebus/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=azure-servicebus:application-cloudevents
+groupId=org.apache.camel
+artifactId=camel-azure-servicebus
+version=4.5.0-SNAPSHOT
+projectName=Camel :: Azure :: ServiceBus
+projectDescription=Camel Azure ServiceBus Component
diff --git a/components/camel-azure/camel-azure-servicebus/src/generated/resources/META-INF/services/org/apache/camel/transformer/azure-servicebus-application-cloudevents b/components/camel-azure/camel-azure-servicebus/src/generated/resources/META-INF/services/org/apache/camel/transformer/azure-servicebus-application-cloudevents
new file mode 100644
index 00000000000..7d1bb6825d4
--- /dev/null
+++ b/components/camel-azure/camel-azure-servicebus/src/generated/resources/META-INF/services/org/apache/camel/transformer/azure-servicebus-application-cloudevents
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.azure.servicebus.transform.ServicebusCloudEventDataTypeTransformer
diff --git a/components/camel-azure/camel-azure-servicebus/src/generated/resources/META-INF/services/org/apache/camel/transformer/azure-servicebus-application-cloudevents.json b/components/camel-azure/camel-azure-servicebus/src/generated/resources/META-INF/services/org/apache/camel/transformer/azure-servicebus-application-cloudevents.json
new file mode 100644
index 00000000000..787aef0b8b2
--- /dev/null
+++ b/components/camel-azure/camel-azure-servicebus/src/generated/resources/META-INF/services/org/apache/camel/transformer/azure-servicebus-application-cloudevents.json
@@ -0,0 +1,14 @@
+{
+ "transformer": {
+ "kind": "transformer",
+ "name": "azure-servicebus:application-cloudevents",
+ "title": "Azure Servicebus (Application Cloudevents)",
+ "description": "Adds CloudEvent headers to the Camel message with Azure Service bus receive messages response details",
+ "deprecated": false,
+ "javaType": "org.apache.camel.component.azure.servicebus.transform.ServicebusCloudEventDataTypeTransformer",
+ "groupId": "org.apache.camel",
+ "artifactId": "camel-azure-servicebus",
+ "version": "4.5.0-SNAPSHOT"
+ }
+}
+
diff --git a/components/camel-azure/camel-azure-servicebus/src/main/java/org/apache/camel/component/azure/servicebus/transform/ServicebusCloudEventDataTypeTransformer.java b/components/camel-azure/camel-azure-servicebus/src/main/java/org/apache/camel/component/azure/servicebus/transform/ServicebusCloudEventDataTypeTransformer.java
new file mode 100644
index 00000000000..db62afee436
--- /dev/null
+++ b/components/camel-azure/camel-azure-servicebus/src/main/java/org/apache/camel/component/azure/servicebus/transform/ServicebusCloudEventDataTypeTransformer.java
@@ -0,0 +1,60 @@
+/*
+ * 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.servicebus.transform;
+
+import org.apache.camel.Message;
+import org.apache.camel.component.azure.servicebus.ServiceBusConstants;
+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 Azure Service bus receive messages response to CloudEvent v1_0 data format. The data type sets Camel
+ * specific CloudEvent headers with values extracted from Azure Service bus receive messages response.
+ */
+@DataTypeTransformer(name = "azure-servicebus:application-cloudevents",
+ description = "Adds CloudEvent headers to the Camel message with Azure Service bus receive messages response details")
+public class ServicebusCloudEventDataTypeTransformer 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.azure.servicebus.receiveMessages");
+
+ if (message.getHeaders().containsKey(ServiceBusConstants.PARTITION_KEY)) {
+ headers.put(CloudEvent.CAMEL_CLOUD_EVENT_SOURCE,
+ "azure.servicebus.partition." + message.getHeader(ServiceBusConstants.PARTITION_KEY, String.class));
+ }
+
+ headers.put(CloudEvent.CAMEL_CLOUD_EVENT_SUBJECT, message.getHeader(ServiceBusConstants.MESSAGE_ID, String.class));
+ headers.put(CloudEvent.CAMEL_CLOUD_EVENT_TIME, cloudEvent.getEventTime(message.getExchange()));
+ if (message.getHeaders().containsKey(ServiceBusConstants.CONTENT_TYPE)) {
+ headers.put(CloudEvent.CAMEL_CLOUD_EVENT_CONTENT_TYPE, message.getHeaders().containsKey(ServiceBusConstants.CONTENT_TYPE));
+ } else {
+ headers.put(CloudEvent.CAMEL_CLOUD_EVENT_CONTENT_TYPE, CloudEvent.APPLICATION_OCTET_STREAM_MIME_TYPE);
+ }
+ }
+}