This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch 1627 in repository https://gitbox.apache.org/repos/asf/camel-kamelets.git
commit 938f7957cf29042abf3f50f55da8cce74499c228 Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Thu Sep 7 07:40:19 2023 +0200 AWS2-SQS Source: Add CloudEvents Data Type Transformer Signed-off-by: Andrea Cosentino <anco...@gmail.com> --- library/camel-kamelets-utils/pom.xml | 5 +++ .../aws2/sqs/AWS2SQSCloudEventOutputType.java | 47 ++++++++++++++++++++++ .../transformer/aws2-sqs-application-cloudevents | 18 +++++++++ 3 files changed, 70 insertions(+) diff --git a/library/camel-kamelets-utils/pom.xml b/library/camel-kamelets-utils/pom.xml index 5807ed63..cd5e4883 100644 --- a/library/camel-kamelets-utils/pom.xml +++ b/library/camel-kamelets-utils/pom.xml @@ -82,6 +82,11 @@ <artifactId>camel-aws2-s3</artifactId> <scope>provided</scope> </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-aws2-sqs</artifactId> + <scope>provided</scope> + </dependency> <!-- Dependencies for mongodb connection configuration --> <dependency> diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/aws2/sqs/AWS2SQSCloudEventOutputType.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/aws2/sqs/AWS2SQSCloudEventOutputType.java new file mode 100644 index 00000000..e4d71e8e --- /dev/null +++ b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/aws2/sqs/AWS2SQSCloudEventOutputType.java @@ -0,0 +1,47 @@ +/* + * 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.kamelets.utils.format.converter.aws2.sqs; + +import org.apache.camel.Message; +import org.apache.camel.component.aws2.s3.AWS2S3Constants; +import org.apache.camel.component.aws2.sqs.Sqs2Constants; +import org.apache.camel.kamelets.utils.format.converter.utils.CloudEvents; +import org.apache.camel.spi.DataType; +import org.apache.camel.spi.DataTypeTransformer; +import org.apache.camel.spi.Transformer; + +import java.util.Map; + +/** + * Output data type represents AWS SQS receive Message response as CloudEvent V1. The data type sets Camel specific + * CloudEvent headers on the exchange. + */ +@DataTypeTransformer(name = "aws2-sqs:application-cloudevents") +public class AWS2SQSCloudEventOutputType extends Transformer { + + @Override + public void transform(Message message, DataType fromType, DataType toType) { + final Map<String, Object> headers = message.getHeaders(); + + headers.put(CloudEvents.CAMEL_CLOUD_EVENT_ID, message.getExchange().getExchangeId()); + headers.put(CloudEvents.CAMEL_CLOUD_EVENT_TYPE, "org.apache.camel.event.aws.sqs.receiveMessage"); + headers.put(CloudEvents.CAMEL_CLOUD_EVENT_SOURCE, "aws.sqs.queue." + message.getHeader(Sqs2Constants.RECEIPT_HANDLE, String.class)); + headers.put(CloudEvents.CAMEL_CLOUD_EVENT_SUBJECT, message.getHeader(Sqs2Constants.MESSAGE_ID, String.class)); + headers.put(CloudEvents.CAMEL_CLOUD_EVENT_TIME, CloudEvents.getEventTime(message.getExchange())); + } +} diff --git a/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/aws2-sqs-application-cloudevents b/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/aws2-sqs-application-cloudevents new file mode 100644 index 00000000..14d4df6f --- /dev/null +++ b/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/aws2-sqs-application-cloudevents @@ -0,0 +1,18 @@ +# +# 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. +# + +class=org.apache.camel.kamelets.utils.format.converter.aws2.sqs.AWS2SQSCloudEventOutputType \ No newline at end of file