This is an automated email from the ASF dual-hosted git repository. dfoulks pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-examples.git
commit e5c9f80bf4f040c3b4c05c785b8359c1f306c860 Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Thu Apr 1 15:31:43 2021 +0200 A simple example of S3 in Streaming Mode --- .../main-endpointdsl-kafka-aws2-s3/README.adoc | 30 ++++++ examples/main-endpointdsl-kafka-aws2-s3/pom.xml | 106 +++++++++++++++++++++ .../org/apache/camel/example/MyApplication.java | 38 ++++++++ .../org/apache/camel/example/MyRouteBuilder.java | 33 +++++++ .../src/main/resources/application.properties | 29 ++++++ .../src/main/resources/logback.xml | 30 ++++++ 6 files changed, 266 insertions(+) diff --git a/examples/main-endpointdsl-kafka-aws2-s3/README.adoc b/examples/main-endpointdsl-kafka-aws2-s3/README.adoc new file mode 100644 index 0000000..88abc6e --- /dev/null +++ b/examples/main-endpointdsl-kafka-aws2-s3/README.adoc @@ -0,0 +1,30 @@ +== Camel Example Main Endpoint DSL with AWS2 S3 component to Kafka + +This example shows how to use the endpoint DSL in your Camel routes +to define endpoints using type safe fluent builders, which are Java methods +that are compiled. + +The example will poll an S3 bucket and send this to a Kafka topic. + +Notice how you can configure Camel in the `application.properties` file. + +Don't forget to add your AWS Credentials and the bucket name and point to the correct topic. + +=== How to run + +You can run this example using + +[source,sh] +---- +$ mvn camel:run +---- + +=== Help and contributions + +If you hit any problem using Camel or have some feedback, then please +https://camel.apache.org/support.html[let us know]. + +We also love contributors, so +https://camel.apache.org/contributing.html[get involved] :-) + +The Camel riders! diff --git a/examples/main-endpointdsl-kafka-aws2-s3/pom.xml b/examples/main-endpointdsl-kafka-aws2-s3/pom.xml new file mode 100644 index 0000000..c12edee --- /dev/null +++ b/examples/main-endpointdsl-kafka-aws2-s3/pom.xml @@ -0,0 +1,106 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.camel.example</groupId> + <artifactId>examples</artifactId> + <version>3.10.0-SNAPSHOT</version> + </parent> + + <artifactId>camel-example-main-endpointdsl-kafka-aws2-s3</artifactId> + <packaging>jar</packaging> + <name>Camel :: Example :: Main :: Endpoint DSL :: Kafka AWS2 S3</name> + <description>An example for showing standalone Camel with Endpoint DSL and Kafka and AWS2 S3</description> + + <properties> + <category>Beginner</category> + </properties> + + <dependencyManagement> + <dependencies> + <!-- Add Camel BOM --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bom</artifactId> + <version>${camel.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-main</artifactId> + </dependency> + <!-- we use the endpoint-dsl --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-endpointdsl</artifactId> + </dependency> + <!-- we use these 2 camel components in this example --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bean</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-aws2-s3</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-kafka</artifactId> + </dependency> + + <!-- logging --> + <dependency> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-core</artifactId> + <version>${logback-version}</version> + </dependency> + <dependency> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-classic</artifactId> + <version>${logback-version}</version> + </dependency> + + </dependencies> + + <build> + <plugins> + <!-- to run the application --> + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-maven-plugin</artifactId> + <version>${camel.version}</version> + <configuration> + <mainClass>org.apache.camel.example.MyApplication</mainClass> + </configuration> + </plugin> + </plugins> + </build> + +</project> diff --git a/examples/main-endpointdsl-kafka-aws2-s3/src/main/java/org/apache/camel/example/MyApplication.java b/examples/main-endpointdsl-kafka-aws2-s3/src/main/java/org/apache/camel/example/MyApplication.java new file mode 100644 index 0000000..496b37d --- /dev/null +++ b/examples/main-endpointdsl-kafka-aws2-s3/src/main/java/org/apache/camel/example/MyApplication.java @@ -0,0 +1,38 @@ +/* + * 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.example; + +import org.apache.camel.main.Main; + +/** + * Main class that boot the Camel application + */ +public final class MyApplication { + + private MyApplication() { + } + + public static void main(String[] args) throws Exception { + // use Camels Main class + Main main = new Main(); + // and add the routes (you can specify multiple classes) + main.configure().addRoutesBuilder(MyRouteBuilder.class); + // now keep the application running until the JVM is terminated (ctrl + c or sigterm) + main.run(args); + } + +} diff --git a/examples/main-endpointdsl-kafka-aws2-s3/src/main/java/org/apache/camel/example/MyRouteBuilder.java b/examples/main-endpointdsl-kafka-aws2-s3/src/main/java/org/apache/camel/example/MyRouteBuilder.java new file mode 100644 index 0000000..75d11b3 --- /dev/null +++ b/examples/main-endpointdsl-kafka-aws2-s3/src/main/java/org/apache/camel/example/MyRouteBuilder.java @@ -0,0 +1,33 @@ +/* + * 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.example; + +import org.apache.camel.builder.endpoint.EndpointRouteBuilder; +import org.apache.camel.builder.endpoint.dsl.AWS2S3EndpointBuilderFactory; +import software.amazon.awssdk.regions.Region; + +public class MyRouteBuilder extends EndpointRouteBuilder { + + @Override + public void configure() throws Exception { + + + from(kafka("{{kafkaTopic}}").brokers("{{kafkaBrokers}}")) + .log("Kafka Message is: ${body}") + .to(aws2S3("{{bucketName}}").streamMode(true).batchMessageNumber(25).namingStrategy(AWS2S3EndpointBuilderFactory.AWSS3NamingStrategyEnum.progressive).keyName("{{kafkaTopic}}.txt")); + } +} diff --git a/examples/main-endpointdsl-kafka-aws2-s3/src/main/resources/application.properties b/examples/main-endpointdsl-kafka-aws2-s3/src/main/resources/application.properties new file mode 100644 index 0000000..f83da18 --- /dev/null +++ b/examples/main-endpointdsl-kafka-aws2-s3/src/main/resources/application.properties @@ -0,0 +1,29 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +# to configure camel main +# here you can configure options on camel main (see MainConfigurationProperties class) +camel.main.name = Kafka-to-AWS2-S3-Producer + +# properties used in the route +camel.component.aws2-s3.accessKey=xxxx +camel.component.aws2-s3.secretKey=yyyy +camel.component.aws2-s3.region=region +bucketName=mycamel-1 + +kafkaTopic=s3.topic +kafkaBrokers=localhost:9092 diff --git a/examples/main-endpointdsl-kafka-aws2-s3/src/main/resources/logback.xml b/examples/main-endpointdsl-kafka-aws2-s3/src/main/resources/logback.xml new file mode 100644 index 0000000..a798d0b --- /dev/null +++ b/examples/main-endpointdsl-kafka-aws2-s3/src/main/resources/logback.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<configuration> + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> + </encoder> + </appender> + + <root level="INFO"> + <appender-ref ref="STDOUT" /> + </root> +</configuration>