This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch couchbase-log in repository https://gitbox.apache.org/repos/asf/camel-examples.git
commit e5972aeaf4c83b3c855161f59a121cf691a0d987 Author: Andrea Cosentino <[email protected]> AuthorDate: Wed Nov 10 14:26:10 2021 +0100 Added A Couchbase Log example --- examples/couchbase-log/README.adoc | 46 ++++++++++ examples/couchbase-log/pom.xml | 97 ++++++++++++++++++++++ .../org/apache/camel/example/MyApplication.java | 38 +++++++++ .../org/apache/camel/example/MyRouteBuilder.java | 30 +++++++ .../src/main/resources/application.properties | 27 ++++++ .../couchbase-log/src/main/resources/logback.xml | 30 +++++++ 6 files changed, 268 insertions(+) diff --git a/examples/couchbase-log/README.adoc b/examples/couchbase-log/README.adoc new file mode 100644 index 0000000..1257e48 --- /dev/null +++ b/examples/couchbase-log/README.adoc @@ -0,0 +1,46 @@ +== Camel Main Example Couchbase + +This example shows how to use the Camel Main module +to define a route from Couchbase to Log. + +Set your application.properties options correctly. +You'll need also a running kafka broker. + +=== Setting up the Couchbase Container + +First of all run the container + +[source,sh] +---- +docker run -d --name db -p 8091-8094:8091-8094 -p 11210:11210 couchbase:6.5.1 +---- + +Now go to localhost:8091 and create a new cluster with username/password admin/password + +Use the sample bucket beer-sample to populate the bucket. + +Now you're ready to run the example. + +=== How to run + +You can run this example using + +[source,sh] +---- +$ mvn compile +---- + +[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/community/support/[let us know]. + +We also love contributors, so +https://camel.apache.org/community/contributing/[get involved] :-) + +The Camel riders! diff --git a/examples/couchbase-log/pom.xml b/examples/couchbase-log/pom.xml new file mode 100644 index 0000000..339858d --- /dev/null +++ b/examples/couchbase-log/pom.xml @@ -0,0 +1,97 @@ +<?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.13.0-SNAPSHOT</version> + </parent> + + <artifactId>camel-example-main-couchbase</artifactId> + <packaging>jar</packaging> + <name>Camel :: Example :: Main :: Couchbase</name> + <description>An example for showing standalone Camel with Couchbase</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 these 2 camel components in this example --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-log</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-couchbase</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/couchbase-log/src/main/java/org/apache/camel/example/MyApplication.java b/examples/couchbase-log/src/main/java/org/apache/camel/example/MyApplication.java new file mode 100644 index 0000000..496b37d --- /dev/null +++ b/examples/couchbase-log/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/couchbase-log/src/main/java/org/apache/camel/example/MyRouteBuilder.java b/examples/couchbase-log/src/main/java/org/apache/camel/example/MyRouteBuilder.java new file mode 100644 index 0000000..91cec4b --- /dev/null +++ b/examples/couchbase-log/src/main/java/org/apache/camel/example/MyRouteBuilder.java @@ -0,0 +1,30 @@ +/* + * 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.RouteBuilder; + +public class MyRouteBuilder extends RouteBuilder { + + @Override + public void configure() throws Exception { + + from("couchbase:http://{{couchbase.host}}:{{couchbase.port}}?bucket={{couchbase.bucket}}&username={{couchbase.username}}&password={{couchbase.password}}&consumerProcessedStrategy={{couchbase.consumerProcessedStrategy}}") + .to("log:info"); + + } +} diff --git a/examples/couchbase-log/src/main/resources/application.properties b/examples/couchbase-log/src/main/resources/application.properties new file mode 100644 index 0000000..4c061b8 --- /dev/null +++ b/examples/couchbase-log/src/main/resources/application.properties @@ -0,0 +1,27 @@ +## --------------------------------------------------------------------------- +## 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-Azure-Storage-Blob + +couchbase.host=localhost +couchbase.port=8091 +couchbase.username=admin +couchbase.password=password +couchbase.bucket=beer-sample +couchbase.consumerProcessedStrategy=delete diff --git a/examples/couchbase-log/src/main/resources/logback.xml b/examples/couchbase-log/src/main/resources/logback.xml new file mode 100644 index 0000000..a798d0b --- /dev/null +++ b/examples/couchbase-log/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>
