You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2022/09/08 11:10:01 UTC
[camel-examples] branch main updated: Add google pubsub example (#107)
This is an automated email from the ASF dual-hosted git repository.
nfilotto pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-examples.git
The following commit(s) were added to refs/heads/main by this push:
new e872307b Add google pubsub example (#107)
e872307b is described below
commit e872307b8c1a2ba0639ea024868397ecef33510c
Author: Tomas Plevko <tp...@redhat.com>
AuthorDate: Thu Sep 8 13:09:56 2022 +0200
Add google pubsub example (#107)
---
examples/README.adoc | 4 +-
examples/google/README.adoc | 27 ++++++
examples/google/google-pubsub/README.adoc | 30 ++++++
examples/google/google-pubsub/pom.xml | 102 +++++++++++++++++++++
.../org/apache/camel/example/MyApplication.java | 36 ++++++++
.../org/apache/camel/example/MyRouteBuilder.java | 33 +++++++
.../src/main/resources/application.properties | 27 ++++++
.../google-pubsub/src/main/resources/logback.xml | 30 ++++++
examples/google/pom.xml | 43 +++++++++
examples/pom.xml | 1 +
10 files changed, 332 insertions(+), 1 deletion(-)
diff --git a/examples/README.adoc b/examples/README.adoc
index 4582dd2c..4223ce7f 100644
--- a/examples/README.adoc
+++ b/examples/README.adoc
@@ -11,7 +11,7 @@ View the individual example READMEs for details.
== Examples
// examples: START
-Number of Examples: 88 (0 deprecated)
+Number of Examples: 89 (0 deprecated)
[width="100%",cols="4,2,4",options="header"]
|===
@@ -100,6 +100,8 @@ Number of Examples: 88 (0 deprecated)
| link:cassandra-kubernetes/README.adoc[Cassandra Kubernetes] (cassandra-kubernetes) | Cloud | An example with Camel and Cassandra running on Kubernetes
+| link:google/README.adoc[Google] (google) | Cloud | Multiple Camel Google examples
+
| link:hazelcast-kubernetes/README.adoc[Hazelcast Kubernetes] (hazelcast-kubernetes) | Cloud | An example with Camel and Hazelcast running on Kubernetes
| link:main-endpointdsl-aws2/README.adoc[Main Endpointdsl Aws2] (main-endpointdsl-aws2) | Cloud | An example for showing standalone Camel with multiple AWS2 components
diff --git a/examples/google/README.adoc b/examples/google/README.adoc
new file mode 100644
index 00000000..9abe17f3
--- /dev/null
+++ b/examples/google/README.adoc
@@ -0,0 +1,27 @@
+= Welcome to the Apache Camel Examples
+
+== Introduction
+
+This directory contains examples for Camel Google cloud components.
+View the individual example READMEs for details.
+
+== Examples
+
+[width="100%",cols="4,2,4",options="header"]
+|===
+| Example | Category | Description
+
+
+| link:google-pubsub/README.adoc[Google Pubsub] (google-pubsub) | Cloud | Google Pubsub example
+
+|===
+
+== 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/google/google-pubsub/README.adoc b/examples/google/google-pubsub/README.adoc
new file mode 100644
index 00000000..a1004ab7
--- /dev/null
+++ b/examples/google/google-pubsub/README.adoc
@@ -0,0 +1,30 @@
+== Camel Example Main Endpoint DSL with Google Pubsub
+
+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 publish messages to Google Cloud PubSub topic and consume them from the affiliated subscription
+
+Notice how you can configure Camel in the `application.properties` file.
+
+Don't forget to correctly set the credentials options in the application properties file
+
+=== 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/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/google/google-pubsub/pom.xml b/examples/google/google-pubsub/pom.xml
new file mode 100644
index 00000000..d6146e74
--- /dev/null
+++ b/examples/google/google-pubsub/pom.xml
@@ -0,0 +1,102 @@
+<?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>camel-examples-google-parent</artifactId>
+ <version>3.19.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-example-google-pubsub</artifactId>
+ <packaging>jar</packaging>
+ <name>Camel :: Example :: Google Pubsub</name>
+ <description>Google Pubsub example</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-timer</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-google-pubsub</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/google/google-pubsub/src/main/java/org/apache/camel/example/MyApplication.java b/examples/google/google-pubsub/src/main/java/org/apache/camel/example/MyApplication.java
new file mode 100644
index 00000000..31197dc0
--- /dev/null
+++ b/examples/google/google-pubsub/src/main/java/org/apache/camel/example/MyApplication.java
@@ -0,0 +1,36 @@
+/*
+ * 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(MyApplication.class);
+ // now keep the application running until the JVM is terminated (ctrl + c or sigterm)
+ main.run(args);
+ }
+
+}
diff --git a/examples/google/google-pubsub/src/main/java/org/apache/camel/example/MyRouteBuilder.java b/examples/google/google-pubsub/src/main/java/org/apache/camel/example/MyRouteBuilder.java
new file mode 100644
index 00000000..8aaeb674
--- /dev/null
+++ b/examples/google/google-pubsub/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;
+
+/**
+ * To use the endpoint DSL then we must extend EndpointRouteBuilder instead of RouteBuilder
+ */
+public class MyRouteBuilder extends EndpointRouteBuilder {
+
+ @Override
+ public void configure() {
+ from(googlePubsub("{{projectId}}:{{subscriptionName}}").serviceAccountKey("{{serviceAccountKey}}")).log("The content is ${body}");
+
+ from(timer("tick").period(1000)).setBody(constant("Event Test"))
+ .to(googlePubsub("{{projectId}}:{{topicName}}").serviceAccountKey("{{serviceAccountKey}}"));
+ }
+}
diff --git a/examples/google/google-pubsub/src/main/resources/application.properties b/examples/google/google-pubsub/src/main/resources/application.properties
new file mode 100644
index 00000000..5f4383d7
--- /dev/null
+++ b/examples/google/google-pubsub/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.
+## ---------------------------------------------------------------------------
+
+# here you can configure options on camel main
+# https://camel.apache.org/components/next/others/main.html
+camel.main.name = Google-PubSub
+
+# properties used in the route
+
+serviceAccountKey=base64:xxxx
+projectId=xxxx
+topicName=xxxx
+subscriptionName=xxxx
diff --git a/examples/google/google-pubsub/src/main/resources/logback.xml b/examples/google/google-pubsub/src/main/resources/logback.xml
new file mode 100644
index 00000000..a798d0b3
--- /dev/null
+++ b/examples/google/google-pubsub/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>
diff --git a/examples/google/pom.xml b/examples/google/pom.xml
new file mode 100644
index 00000000..7121ffc1
--- /dev/null
+++ b/examples/google/pom.xml
@@ -0,0 +1,43 @@
+<?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.19.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-examples-google-parent</artifactId>
+ <name>Camel :: Example :: Google :: Parent</name>
+ <description>Multiple Camel Google examples</description>
+ <packaging>pom</packaging>
+
+ <properties>
+ <category>Cloud</category>
+ </properties>
+
+ <modules>
+ <module>google-pubsub</module>
+ </modules>
+
+</project>
diff --git a/examples/pom.xml b/examples/pom.xml
index 51fd497a..07af974a 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -108,6 +108,7 @@
<module>fhir</module>
<module>flight-recorder</module>
<module>ftp</module>
+ <module>google</module>
<module>hazelcast-kubernetes</module>
<module>java8</module>
<module>jdbc</module>