You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/11/28 00:26:15 UTC
[camel-quarkus] branch master updated: Add MongoDB extension
This is an automated email from the ASF dual-hosted git repository.
lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/master by this push:
new 2fdbb4e Add MongoDB extension
2fdbb4e is described below
commit 2fdbb4e5488f83a11364838022837ddd3fba94ee
Author: James Netherton <ja...@gmail.com>
AuthorDate: Wed Nov 27 15:21:10 2019 +0000
Add MongoDB extension
fixes #302
---
docs/modules/ROOT/pages/extensions/mongodb.adoc | 31 +++++
.../pages/list-of-camel-quarkus-extensions.adoc | 5 +-
extensions/mongodb/deployment/pom.xml | 79 ++++++++++++
.../mongodb/deployment/MongoDbProcessor.java | 47 +++++++
extensions/mongodb/pom.xml | 39 ++++++
extensions/mongodb/runtime/pom.xml | 86 +++++++++++++
.../component/mongodb/CamelMongoClient.java | 125 +++++++++++++++++++
.../mongodb/CamelMongoClientRecorder.java | 30 +++++
.../main/resources/META-INF/quarkus-extension.yaml | 30 +++++
extensions/pom.xml | 1 +
extensions/readme.adoc | 5 +-
integration-tests/mongodb/pom.xml | 137 +++++++++++++++++++++
.../component/mongodb/it/MongoDbResource.java | 86 +++++++++++++
.../quarkus/component/mongodb/it/MongoDbIT.java | 24 ++++
.../quarkus/component/mongodb/it/MongoDbTest.java | 87 +++++++++++++
integration-tests/pom.xml | 1 +
poms/bom-deployment/pom.xml | 5 +
poms/bom/pom.xml | 16 +++
18 files changed, 832 insertions(+), 2 deletions(-)
diff --git a/docs/modules/ROOT/pages/extensions/mongodb.adoc b/docs/modules/ROOT/pages/extensions/mongodb.adoc
new file mode 100644
index 0000000..b3643c5
--- /dev/null
+++ b/docs/modules/ROOT/pages/extensions/mongodb.adoc
@@ -0,0 +1,31 @@
+[[mongodb]]
+= MongoDB Extension
+
+*Since Camel Quarkus 0.5.0*
+
+The MongoDB component provides the capability to interact with MongoDB servers.
+
+Maven users will need to add the following dependency to their `pom.xml` for this extension.
+
+[source,xml]
+------------------------------------------------------------
+<dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-mongodb</artifactId>
+</dependency>
+------------------------------------------------------------
+
+== Usage
+
+The extension provides support for the Camel https://camel.apache.org/components/latest/mongodb-component.html[MongoDB Component].
+
+=== Configuration
+
+The extension leverages the https://quarkus.io/guides/mongodb[Quarkus MongoDB Client] extension. The Mongo client can be configured
+via the Quarkus MongoDB Client https://quarkus.io/guides/mongodb#configuration-reference[configuration options].
+
+The Camel Quarkus MongoDB extension automatically registers a MongoDB client bean named `camelMongoClient`. This can be referenced in the mongodb endpoint URI
+`connectionBean` path parameter. For example:
+
+ from("direct:start")
+ .to("mongodb:camelMongoClient?database=myDb&collection=myCollection&operation=findAll")
diff --git a/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc b/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc
index 0293752..1b94427 100644
--- a/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc
+++ b/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc
@@ -6,7 +6,7 @@ As of Camel Quarkus {camel-quarkus-last-release} the following Camel artifacts a
== Camel Components
// components: START
-Number of Camel components: 45 in 38 JAR artifacts (0 deprecated)
+Number of Camel components: 46 in 39 JAR artifacts (0 deprecated)
[width="100%",cols="4,1,5",options="header"]
|===
@@ -84,6 +84,9 @@ Number of Camel components: 45 in 38 JAR artifacts (0 deprecated)
| xref:extensions/microprofile-metrics.adoc[MicroProfile Metrics] (camel-quarkus-microprofile-metrics) +
`microprofile-metrics:metricType:metricName` | 0.2 | Camel metrics exposed with Eclipse MicroProfile Metrics
+| xref:extensions/mongodb.adoc[MongoDB] (camel-quarkus-mongodb) +
+`mongodb:connectionBean` | 0.5 | Component for working with documents stored in MongoDB database.
+
| xref:extensions/netty.adoc[Netty] (camel-quarkus-netty) +
`netty:protocol:host:port` | 0.4 | Socket level networking using TCP or UDP with the Netty 4.x library.
diff --git a/extensions/mongodb/deployment/pom.xml b/extensions/mongodb/deployment/pom.xml
new file mode 100644
index 0000000..414528d
--- /dev/null
+++ b/extensions/mongodb/deployment/pom.xml
@@ -0,0 +1,79 @@
+<?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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-mongodb-parent</artifactId>
+ <version>0.4.1-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>camel-quarkus-mongodb-deployment</artifactId>
+ <name>Camel Quarkus :: MongoDB :: Deployment</name>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-bom-deployment</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-core-deployment</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-mongodb-client-deployment</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-mongodb</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <annotationProcessorPaths>
+ <path>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-extension-processor</artifactId>
+ <version>${quarkus.version}</version>
+ </path>
+ </annotationProcessorPaths>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/extensions/mongodb/deployment/src/main/java/org/apache/camel/quarkus/component/mongodb/deployment/MongoDbProcessor.java b/extensions/mongodb/deployment/src/main/java/org/apache/camel/quarkus/component/mongodb/deployment/MongoDbProcessor.java
new file mode 100644
index 0000000..2e23bf8
--- /dev/null
+++ b/extensions/mongodb/deployment/src/main/java/org/apache/camel/quarkus/component/mongodb/deployment/MongoDbProcessor.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.quarkus.component.mongodb.deployment;
+
+import io.quarkus.deployment.annotations.BuildStep;
+import io.quarkus.deployment.annotations.ExecutionTime;
+import io.quarkus.deployment.annotations.Record;
+import io.quarkus.deployment.builditem.FeatureBuildItem;
+import io.quarkus.mongodb.deployment.MongoClientBuildItem;
+
+import com.mongodb.MongoClient;
+
+import org.apache.camel.quarkus.component.mongodb.CamelMongoClientRecorder;
+import org.apache.camel.quarkus.core.deployment.CamelRuntimeBeanBuildItem;
+
+class MongoDbProcessor {
+
+ private static final String FEATURE = "camel-mongodb";
+
+ @BuildStep
+ FeatureBuildItem feature() {
+ return new FeatureBuildItem(FEATURE);
+ }
+
+ @BuildStep
+ @Record(ExecutionTime.RUNTIME_INIT)
+ CamelRuntimeBeanBuildItem registerCamelMongoClientProducer(MongoClientBuildItem mongoClientBuildItem,
+ CamelMongoClientRecorder recorder) {
+
+ return new CamelRuntimeBeanBuildItem("camelMongoClient", MongoClient.class.getName(),
+ recorder.createCamelMongoClient(mongoClientBuildItem.getClient()));
+ }
+}
diff --git a/extensions/mongodb/pom.xml b/extensions/mongodb/pom.xml
new file mode 100644
index 0000000..3224572
--- /dev/null
+++ b/extensions/mongodb/pom.xml
@@ -0,0 +1,39 @@
+<?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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-build-parent</artifactId>
+ <version>0.4.1-SNAPSHOT</version>
+ <relativePath>../../poms/build-parent/pom.xml</relativePath>
+ </parent>
+
+ <artifactId>camel-quarkus-mongodb-parent</artifactId>
+ <name>Camel Quarkus :: MongoDB</name>
+ <packaging>pom</packaging>
+
+ <modules>
+ <module>deployment</module>
+ <module>runtime</module>
+ </modules>
+</project>
diff --git a/extensions/mongodb/runtime/pom.xml b/extensions/mongodb/runtime/pom.xml
new file mode 100644
index 0000000..106c8e0
--- /dev/null
+++ b/extensions/mongodb/runtime/pom.xml
@@ -0,0 +1,86 @@
+<?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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-mongodb-parent</artifactId>
+ <version>0.4.1-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>camel-quarkus-mongodb</artifactId>
+ <name>Camel Quarkus :: MongoDB :: Runtime</name>
+
+ <properties>
+ <firstVersion>0.5.0</firstVersion>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-bom</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-mongodb</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-mongodb-client</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-bootstrap-maven-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <annotationProcessorPaths>
+ <path>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-extension-processor</artifactId>
+ <version>${quarkus.version}</version>
+ </path>
+ </annotationProcessorPaths>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/extensions/mongodb/runtime/src/main/java/org/apache/camel/quarkus/component/mongodb/CamelMongoClient.java b/extensions/mongodb/runtime/src/main/java/org/apache/camel/quarkus/component/mongodb/CamelMongoClient.java
new file mode 100644
index 0000000..0e485f0
--- /dev/null
+++ b/extensions/mongodb/runtime/src/main/java/org/apache/camel/quarkus/component/mongodb/CamelMongoClient.java
@@ -0,0 +1,125 @@
+/*
+ * 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.quarkus.component.mongodb;
+
+import java.util.List;
+
+import com.mongodb.ClientSessionOptions;
+import com.mongodb.client.ChangeStreamIterable;
+import com.mongodb.client.ClientSession;
+import com.mongodb.client.ListDatabasesIterable;
+import com.mongodb.client.MongoClient;
+import com.mongodb.client.MongoDatabase;
+import com.mongodb.client.MongoIterable;
+
+import org.bson.Document;
+import org.bson.conversions.Bson;
+
+/**
+ * Bridges Mongo client types {@link com.mongodb.MongoClient} and {@link com.mongodb.client.MongoClient} used by the
+ * Quarkus Mongo extension and the Camel MongoDB component, so that it can be looked up and used via the
+ * connectionBean URI endpoint path parameter
+ */
+public final class CamelMongoClient extends com.mongodb.MongoClient {
+
+ private final MongoClient delegate;
+
+ public CamelMongoClient(MongoClient delegate) {
+ this.delegate = delegate;
+ }
+
+ @Override
+ public MongoDatabase getDatabase(String databaseName) {
+ return delegate.getDatabase(databaseName);
+ }
+
+ @Override
+ public ClientSession startSession() {
+ return delegate.startSession();
+ }
+
+ @Override
+ public ClientSession startSession(ClientSessionOptions options) {
+ return delegate.startSession(options);
+ }
+
+ @Override
+ public void close() {
+ delegate.close();
+ }
+
+ @Override
+ public MongoIterable<String> listDatabaseNames() {
+ return delegate.listDatabaseNames();
+ }
+
+ @Override
+ public ListDatabasesIterable<Document> listDatabases(ClientSession clientSession) {
+ return delegate.listDatabases(clientSession);
+ }
+
+ @Override
+ public <T> ListDatabasesIterable<T> listDatabases(ClientSession clientSession, Class<T> clazz) {
+ return delegate.listDatabases(clientSession, clazz);
+ }
+
+ @Override
+ public <T> ListDatabasesIterable<T> listDatabases(Class<T> clazz) {
+ return delegate.listDatabases(clazz);
+ }
+
+ @Override
+ public ChangeStreamIterable<Document> watch() {
+ return delegate.watch();
+ }
+
+ @Override
+ public ChangeStreamIterable<Document> watch(List<? extends Bson> pipeline) {
+ return delegate.watch(pipeline);
+ }
+
+ @Override
+ public ChangeStreamIterable<Document> watch(ClientSession clientSession) {
+ return delegate.watch(clientSession);
+ }
+
+ @Override
+ public ChangeStreamIterable<Document> watch(ClientSession clientSession, List<? extends Bson> pipeline) {
+ return delegate.watch(clientSession, pipeline);
+ }
+
+ @Override
+ public <TResult> ChangeStreamIterable<TResult> watch(Class<TResult> resultClass) {
+ return delegate.watch(resultClass);
+ }
+
+ @Override
+ public <TResult> ChangeStreamIterable<TResult> watch(List<? extends Bson> pipeline, Class<TResult> resultClass) {
+ return delegate.watch(pipeline, resultClass);
+ }
+
+ @Override
+ public <TResult> ChangeStreamIterable<TResult> watch(ClientSession clientSession, Class<TResult> resultClass) {
+ return delegate.watch(clientSession, resultClass);
+ }
+
+ @Override
+ public <TResult> ChangeStreamIterable<TResult> watch(ClientSession clientSession, List<? extends Bson> pipeline,
+ Class<TResult> resultClass) {
+ return delegate.watch(clientSession, pipeline, resultClass);
+ }
+}
diff --git a/extensions/mongodb/runtime/src/main/java/org/apache/camel/quarkus/component/mongodb/CamelMongoClientRecorder.java b/extensions/mongodb/runtime/src/main/java/org/apache/camel/quarkus/component/mongodb/CamelMongoClientRecorder.java
new file mode 100644
index 0000000..bc9f760
--- /dev/null
+++ b/extensions/mongodb/runtime/src/main/java/org/apache/camel/quarkus/component/mongodb/CamelMongoClientRecorder.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.quarkus.component.mongodb;
+
+import io.quarkus.runtime.RuntimeValue;
+import io.quarkus.runtime.annotations.Recorder;
+
+import com.mongodb.client.MongoClient;
+
+@Recorder
+public class CamelMongoClientRecorder {
+
+ public RuntimeValue<CamelMongoClient> createCamelMongoClient(RuntimeValue<MongoClient> client) {
+ return new RuntimeValue<>(new CamelMongoClient(client.getValue()));
+ }
+}
diff --git a/extensions/mongodb/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/mongodb/runtime/src/main/resources/META-INF/quarkus-extension.yaml
new file mode 100644
index 0000000..787644f
--- /dev/null
+++ b/extensions/mongodb/runtime/src/main/resources/META-INF/quarkus-extension.yaml
@@ -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.
+#
+
+---
+name: "Camel Quarkus MongoDB"
+description: "Camel Java MongoDB support"
+metadata:
+ keywords:
+ - "camel"
+ - "mongo"
+ - "mongodb"
+ - "nosql"
+ - "datastore"
+ guide: "https://quarkus.io/guides/camel"
+ categories:
+ - "integration"
\ No newline at end of file
diff --git a/extensions/pom.xml b/extensions/pom.xml
index bdfa35b..069d68b 100644
--- a/extensions/pom.xml
+++ b/extensions/pom.xml
@@ -68,6 +68,7 @@
<module>mail</module>
<module>microprofile-health</module>
<module>microprofile-metrics</module>
+ <module>mongodb</module>
<module>netty</module>
<module>netty-http</module>
<module>opentracing</module>
diff --git a/extensions/readme.adoc b/extensions/readme.adoc
index 12efa33..4947299 100644
--- a/extensions/readme.adoc
+++ b/extensions/readme.adoc
@@ -5,7 +5,7 @@ Apache Camel Quarkus supports the following Camel artifacts as Quarkus Extension
== Camel Components
// components: START
-Number of Camel components: 45 in 38 JAR artifacts (0 deprecated)
+Number of Camel components: 46 in 39 JAR artifacts (0 deprecated)
[width="100%",cols="4,1,5",options="header"]
|===
@@ -83,6 +83,9 @@ Number of Camel components: 45 in 38 JAR artifacts (0 deprecated)
| xref:extensions/microprofile-metrics.adoc[MicroProfile Metrics] (camel-quarkus-microprofile-metrics) +
`microprofile-metrics:metricType:metricName` | 0.2 | Camel metrics exposed with Eclipse MicroProfile Metrics
+| xref:extensions/mongodb.adoc[MongoDB] (camel-quarkus-mongodb) +
+`mongodb:connectionBean` | 0.5 | Component for working with documents stored in MongoDB database.
+
| xref:extensions/netty.adoc[Netty] (camel-quarkus-netty) +
`netty:protocol:host:port` | 0.4 | Socket level networking using TCP or UDP with the Netty 4.x library.
diff --git a/integration-tests/mongodb/pom.xml b/integration-tests/mongodb/pom.xml
new file mode 100644
index 0000000..d5efe8a
--- /dev/null
+++ b/integration-tests/mongodb/pom.xml
@@ -0,0 +1,137 @@
+<?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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-integration-tests</artifactId>
+ <version>0.4.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-quarkus-integration-test-mongodb</artifactId>
+ <name>Camel Quarkus :: Integration Tests :: MongoDB</name>
+ <description>Integration tests for Camel Quarkus MongoDB extension</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-mongodb</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-resteasy</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-resteasy-jsonb</artifactId>
+ </dependency>
+
+ <!-- test dependencies -->
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-junit5</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.rest-assured</groupId>
+ <artifactId>rest-assured</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>de.flapdoodle.embed</groupId>
+ <artifactId>de.flapdoodle.embed.mongo</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>build</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>native</id>
+ <activation>
+ <property>
+ <name>native</name>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ <configuration>
+ <systemProperties>
+ <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
+ </systemProperties>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>native-image</id>
+ <goals>
+ <goal>native-image</goal>
+ </goals>
+ <configuration>
+ <reportErrorsAtRuntime>false</reportErrorsAtRuntime>
+ <cleanupServer>true</cleanupServer>
+ <enableHttpsUrlHandler>true</enableHttpsUrlHandler>
+ <enableServer>false</enableServer>
+ <dumpProxies>false</dumpProxies>
+ <graalvmHome>${graalvmHome}</graalvmHome>
+ <enableJni>true</enableJni>
+ <enableAllSecurityServices>true</enableAllSecurityServices>
+ <disableReports>true</disableReports>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+</project>
diff --git a/integration-tests/mongodb/src/main/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbResource.java b/integration-tests/mongodb/src/main/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbResource.java
new file mode 100644
index 0000000..9022649
--- /dev/null
+++ b/integration-tests/mongodb/src/main/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbResource.java
@@ -0,0 +1,86 @@
+/*
+ * 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.quarkus.component.mongodb.it;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.json.Json;
+import javax.json.JsonArray;
+import javax.json.JsonArrayBuilder;
+import javax.json.JsonObjectBuilder;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import com.mongodb.client.MongoCursor;
+import com.mongodb.client.MongoIterable;
+
+import org.apache.camel.ProducerTemplate;
+import org.bson.Document;
+
+@Path("/mongodb")
+@ApplicationScoped
+public class MongoDbResource {
+
+ @Inject
+ ProducerTemplate producerTemplate;
+
+ @POST
+ @Path("/collection/{collectionName}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ public Response writeToCollection(@PathParam("collectionName") String collectionName, String content)
+ throws URISyntaxException {
+
+ producerTemplate.sendBody(
+ "mongodb:camelMongoClient?database=test&collection=" + collectionName + "&operation=insert&dynamicity=true",
+ content);
+
+ return Response
+ .created(new URI("https://camel.apache.org/"))
+ .build();
+ }
+
+ @GET
+ @Path("/collection/{collectionName}")
+ @Produces(MediaType.APPLICATION_JSON)
+ public JsonArray getCollection(@PathParam("collectionName") String collectionName) {
+ JsonArrayBuilder arrayBuilder = Json.createArrayBuilder();
+
+ MongoIterable<Document> iterable = producerTemplate.requestBody(
+ "mongodb:camelMongoClient?database=test&collection=" + collectionName
+ + "&operation=findAll&dynamicity=true&outputType=MongoIterable",
+ null, MongoIterable.class);
+
+ MongoCursor<Document> iterator = iterable.iterator();
+ while (iterator.hasNext()) {
+ Document document = iterator.next();
+ JsonObjectBuilder objectBuilder = Json.createObjectBuilder();
+ objectBuilder.add("message", (String) document.get("message"));
+ arrayBuilder.add(objectBuilder.build());
+ }
+
+ return arrayBuilder.build();
+ }
+}
diff --git a/integration-tests/mongodb/src/test/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbIT.java b/integration-tests/mongodb/src/test/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbIT.java
new file mode 100644
index 0000000..2a6e146
--- /dev/null
+++ b/integration-tests/mongodb/src/test/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbIT.java
@@ -0,0 +1,24 @@
+/*
+ * 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.quarkus.component.mongodb.it;
+
+import io.quarkus.test.junit.NativeImageTest;
+
+@NativeImageTest
+class MongoDbIT extends MongoDbTest {
+
+}
diff --git a/integration-tests/mongodb/src/test/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbTest.java b/integration-tests/mongodb/src/test/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbTest.java
new file mode 100644
index 0000000..688746f
--- /dev/null
+++ b/integration-tests/mongodb/src/test/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbTest.java
@@ -0,0 +1,87 @@
+/*
+ * 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.quarkus.component.mongodb.it;
+
+import de.flapdoodle.embed.mongo.MongodExecutable;
+import de.flapdoodle.embed.mongo.MongodStarter;
+import de.flapdoodle.embed.mongo.config.IMongodConfig;
+import de.flapdoodle.embed.mongo.config.MongodConfigBuilder;
+import de.flapdoodle.embed.mongo.config.Net;
+import de.flapdoodle.embed.mongo.distribution.Version;
+import de.flapdoodle.embed.process.runtime.Network;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+import io.restassured.path.json.JsonPath;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+@QuarkusTest
+class MongoDbTest {
+
+ private static MongodExecutable MONGO;
+
+ @BeforeAll
+ public static void beforeAll() throws IOException {
+ IMongodConfig config = new MongodConfigBuilder()
+ .net(new Net(27017, Network.localhostIsIPv6()))
+ .version(Version.Main.V4_0)
+ .build();
+ MONGO = MongodStarter.getDefaultInstance().prepare(config);
+ MONGO.start();
+ }
+
+ @AfterAll
+ public static void afterAll() {
+ if (MONGO != null) {
+ MONGO.stop();
+ }
+ }
+
+ @Test
+ public void testMongoDbComponent() {
+ // Write to collection
+ RestAssured.given()
+ .contentType(ContentType.JSON)
+ .body("{message:\"Hello Camel Quarkus Mongo DB\"}")
+ .post("/mongodb/collection/camelTest")
+ .then()
+ .statusCode(201);
+
+ // Retrieve from collection
+ JsonPath jsonPath = RestAssured.get("/mongodb/collection/camelTest")
+ .then()
+ .contentType(ContentType.JSON)
+ .statusCode(200)
+ .extract()
+ .body()
+ .jsonPath();
+
+ List<Map<String, String>> documents = jsonPath.get();
+ assertEquals(1, documents.size());
+
+ Map<String, String> document = documents.get(0);
+ assertEquals("Hello Camel Quarkus Mongo DB", document.get("message"));
+ }
+}
diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml
index b219a40..6925f25 100644
--- a/integration-tests/pom.xml
+++ b/integration-tests/pom.xml
@@ -114,6 +114,7 @@
<module>kafka</module>
<module>mail</module>
<module>microprofile</module>
+ <module>mongodb</module>
<module>netty</module>
<module>netty-http</module>
<module>opentracing</module>
diff --git a/poms/bom-deployment/pom.xml b/poms/bom-deployment/pom.xml
index 071d706..b7491ec 100644
--- a/poms/bom-deployment/pom.xml
+++ b/poms/bom-deployment/pom.xml
@@ -225,6 +225,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-mongodb-deployment</artifactId>
+ <version>${camel-quarkus.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-netty-http-deployment</artifactId>
<version>${camel-quarkus.version}</version>
</dependency>
diff --git a/poms/bom/pom.xml b/poms/bom/pom.xml
index 5279a99..84bd56f 100644
--- a/poms/bom/pom.xml
+++ b/poms/bom/pom.xml
@@ -253,6 +253,17 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-mongodb</artifactId>
+ <version>${camel.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.mongodb</groupId>
+ <artifactId>mongo-java-driver</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-netty-http</artifactId>
<version>${camel.version}</version>
<exclusions>
@@ -555,6 +566,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-mongodb</artifactId>
+ <version>${camel-quarkus.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-netty</artifactId>
<version>${camel-quarkus.version}</version>
</dependency>