This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch CAMEL-20451 in repository https://gitbox.apache.org/repos/asf/camel.git
commit 561d017e7835165cb34371b7de4a83d84888b2e3 Author: Andrea Cosentino <[email protected]> AuthorDate: Mon Feb 26 11:46:32 2024 +0100 CAMEL-20451 - Azure Eventhubs CloudEvent transformer Signed-off-by: Andrea Cosentino <[email protected]> --- .../apache/camel/catalog/transformers.properties | 1 + .../azure-eventhubs-application-cloudevents.json | 14 ++++++ .../camel-azure/camel-azure-eventhubs/pom.xml | 8 ++++ .../org/apache/camel/transformer.properties | 7 +++ .../azure-eventhubs-application-cloudevents | 2 + .../azure-eventhubs-application-cloudevents.json | 14 ++++++ .../EventHubsCloudEventDataTypeTransformer.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 40d4547cf85..3214c46dcb8 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-cosmosdb-application-cloudevents +azure-eventhubs-application-cloudevents azure-files-application-cloudevents azure-servicebus-application-cloudevents azure-storage-blob-application-cloudevents diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers/azure-eventhubs-application-cloudevents.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers/azure-eventhubs-application-cloudevents.json new file mode 100644 index 00000000000..8af72869a52 --- /dev/null +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/transformers/azure-eventhubs-application-cloudevents.json @@ -0,0 +1,14 @@ +{ + "transformer": { + "kind": "transformer", + "name": "azure-eventhubs:application-cloudevents", + "title": "Azure Eventhubs (Application Cloudevents)", + "description": "Adds CloudEvent headers to the Camel message with Azure Eventhubs consumer response details", + "deprecated": false, + "javaType": "org.apache.camel.component.azure.eventhubs.transform.EventHubsCloudEventDataTypeTransformer", + "groupId": "org.apache.camel", + "artifactId": "camel-azure-eventhubs", + "version": "4.5.0-SNAPSHOT" + } +} + diff --git a/components/camel-azure/camel-azure-eventhubs/pom.xml b/components/camel-azure/camel-azure-eventhubs/pom.xml index 94b2d936aa3..32733a3af7d 100644 --- a/components/camel-azure/camel-azure-eventhubs/pom.xml +++ b/components/camel-azure/camel-azure-eventhubs/pom.xml @@ -62,6 +62,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-eventhubs/src/generated/resources/META-INF/services/org/apache/camel/transformer.properties b/components/camel-azure/camel-azure-eventhubs/src/generated/resources/META-INF/services/org/apache/camel/transformer.properties new file mode 100644 index 00000000000..3a045e94db5 --- /dev/null +++ b/components/camel-azure/camel-azure-eventhubs/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-eventhubs:application-cloudevents +groupId=org.apache.camel +artifactId=camel-azure-eventhubs +version=4.5.0-SNAPSHOT +projectName=Camel :: Azure :: Event Hubs +projectDescription=Camel Azure Event Hubs Component diff --git a/components/camel-azure/camel-azure-eventhubs/src/generated/resources/META-INF/services/org/apache/camel/transformer/azure-eventhubs-application-cloudevents b/components/camel-azure/camel-azure-eventhubs/src/generated/resources/META-INF/services/org/apache/camel/transformer/azure-eventhubs-application-cloudevents new file mode 100644 index 00000000000..fba93cc2a25 --- /dev/null +++ b/components/camel-azure/camel-azure-eventhubs/src/generated/resources/META-INF/services/org/apache/camel/transformer/azure-eventhubs-application-cloudevents @@ -0,0 +1,2 @@ +# Generated by camel build tools - do NOT edit this file! +class=org.apache.camel.component.azure.eventhubs.transform.EventHubsCloudEventDataTypeTransformer diff --git a/components/camel-azure/camel-azure-eventhubs/src/generated/resources/META-INF/services/org/apache/camel/transformer/azure-eventhubs-application-cloudevents.json b/components/camel-azure/camel-azure-eventhubs/src/generated/resources/META-INF/services/org/apache/camel/transformer/azure-eventhubs-application-cloudevents.json new file mode 100644 index 00000000000..8af72869a52 --- /dev/null +++ b/components/camel-azure/camel-azure-eventhubs/src/generated/resources/META-INF/services/org/apache/camel/transformer/azure-eventhubs-application-cloudevents.json @@ -0,0 +1,14 @@ +{ + "transformer": { + "kind": "transformer", + "name": "azure-eventhubs:application-cloudevents", + "title": "Azure Eventhubs (Application Cloudevents)", + "description": "Adds CloudEvent headers to the Camel message with Azure Eventhubs consumer response details", + "deprecated": false, + "javaType": "org.apache.camel.component.azure.eventhubs.transform.EventHubsCloudEventDataTypeTransformer", + "groupId": "org.apache.camel", + "artifactId": "camel-azure-eventhubs", + "version": "4.5.0-SNAPSHOT" + } +} + diff --git a/components/camel-azure/camel-azure-eventhubs/src/main/java/org/apache/camel/component/azure/eventhubs/transform/EventHubsCloudEventDataTypeTransformer.java b/components/camel-azure/camel-azure-eventhubs/src/main/java/org/apache/camel/component/azure/eventhubs/transform/EventHubsCloudEventDataTypeTransformer.java new file mode 100644 index 00000000000..85a9ca2e357 --- /dev/null +++ b/components/camel-azure/camel-azure-eventhubs/src/main/java/org/apache/camel/component/azure/eventhubs/transform/EventHubsCloudEventDataTypeTransformer.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.eventhubs.transform; + +import org.apache.camel.Message; +import org.apache.camel.component.azure.eventhubs.EventHubsConstants; +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 Eventhubs consumer response to CloudEvent v1_0 data format. The data type sets + * Camel specific CloudEvent headers with values extracted from Azure Eventhubs consumer response. + */ +@DataTypeTransformer(name = "azure-eventhubs:application-cloudevents", + description = "Adds CloudEvent headers to the Camel message with Azure Eventhubs consumer response details") +public class EventHubsCloudEventDataTypeTransformer 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.eventhubs.consume"); + + if (message.getHeaders().containsKey(EventHubsConstants.PARTITION_ID)) { + headers.put(CloudEvent.CAMEL_CLOUD_EVENT_SOURCE, + "azure.eventhubs." + message.getHeader(EventHubsConstants.PARTITION_ID, String.class)); + } + + headers.put(CloudEvent.CAMEL_CLOUD_EVENT_SUBJECT, message.getHeader(EventHubsConstants.SEQUENCE_NUMBER, Long.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); + } +}
