This is an automated email from the ASF dual-hosted git repository.

aldettinger pushed a commit to branch data-extraction-example
in repository https://gitbox.apache.org/repos/asf/camel-quarkus-examples.git

commit 5eba86d2bddb2ab1b7e3fe03cd17beaa624517f5
Author: aldettinger <aldettin...@gmail.com>
AuthorDate: Wed Aug 21 15:36:08 2024 +0200

    First version where cq-mongodb is able to consume messages
---
 data-extract-langchain4j/pom.xml                   |  4 ++
 .../src/main/java/org/acme/extraction/Routes.java  |  3 +
 .../src/main/resources/application.properties      |  3 +
 .../org/acme/extraction/MongoDbTestResource.java   | 83 ++++++++++++++++++++++
 .../test/java/org/acme/extraction/RouteTest.java   |  1 +
 .../src/test/resources/mongodb/mongo-init.js       | 22 ++++++
 6 files changed, 116 insertions(+)

diff --git a/data-extract-langchain4j/pom.xml b/data-extract-langchain4j/pom.xml
index ce159e3..52e90a9 100644
--- a/data-extract-langchain4j/pom.xml
+++ b/data-extract-langchain4j/pom.xml
@@ -87,6 +87,10 @@
             <groupId>org.apache.camel.quarkus</groupId>
             <artifactId>camel-quarkus-bean</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-mongodb</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.apache.camel.quarkus</groupId>
             <artifactId>camel-quarkus-platform-http</artifactId>
diff --git 
a/data-extract-langchain4j/src/main/java/org/acme/extraction/Routes.java 
b/data-extract-langchain4j/src/main/java/org/acme/extraction/Routes.java
index 03593e3..2d3991e 100644
--- a/data-extract-langchain4j/src/main/java/org/acme/extraction/Routes.java
+++ b/data-extract-langchain4j/src/main/java/org/acme/extraction/Routes.java
@@ -16,6 +16,9 @@ public class Routes extends RouteBuilder {
                 .log("Received ${body}")
                 .bean(customPojoExtractionService)
                 .bean(this, "toPrettyFormat");
+
+        
fromF("mongodb:myMongoClient?database=transcripts_db&collection=transcripts_collection")
+                .log("!!!!!!!!!!!!!!!! Mongo Received ${body}");
     }
 
     private final static String FORMAT = "{"
diff --git a/data-extract-langchain4j/src/main/resources/application.properties 
b/data-extract-langchain4j/src/main/resources/application.properties
index bd81e19..f440aac 100644
--- a/data-extract-langchain4j/src/main/resources/application.properties
+++ b/data-extract-langchain4j/src/main/resources/application.properties
@@ -35,6 +35,9 @@ quarkus.langchain4j.ollama.chat-model.temperature = 0
 # Uncomment if your application image is to be pushed to an external registry
 #quarkus.container-image.registry=my.docker-registry.net
 
+# MongoDB
+quarkus.mongodb.devservices.enabled=false
+
 # Kubernetes
 
 # Uncomment to trust self signed certificates if they are presented by the 
Kubernetes API server
diff --git 
a/data-extract-langchain4j/src/test/java/org/acme/extraction/MongoDbTestResource.java
 
b/data-extract-langchain4j/src/test/java/org/acme/extraction/MongoDbTestResource.java
new file mode 100644
index 0000000..8df63ae
--- /dev/null
+++ 
b/data-extract-langchain4j/src/test/java/org/acme/extraction/MongoDbTestResource.java
@@ -0,0 +1,83 @@
+/*
+ * 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.acme.extraction;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.containers.wait.strategy.Wait;
+import org.testcontainers.utility.TestcontainersConfiguration;
+
+import static org.testcontainers.utility.MountableFile.forClasspathResource;
+
+public class MongoDbTestResource implements 
QuarkusTestResourceLifecycleManager {
+    private static final Logger LOG = 
LoggerFactory.getLogger(MongoDbTestResource.class);
+
+    private static final int MONGODB_PORT = 27017;
+    private static final String MONGODB_IMAGE = "docker.io/mongo:4.4";
+    private static final String MONGODB_ROOT_USERNAME = "admin";
+    private static final String MONGODB_ROOT_PASSWORD = "password";
+
+    private GenericContainer<?> container;
+
+    @Override
+    public Map<String, String> start() {
+        LOG.info(TestcontainersConfiguration.getInstance().toString());
+
+        try {
+            container = new GenericContainer(MONGODB_IMAGE)
+                    .withExposedPorts(MONGODB_PORT)
+                    .withEnv("MONGO_INITDB_ROOT_USERNAME", 
MONGODB_ROOT_USERNAME)
+                    .withEnv("MONGO_INITDB_ROOT_PASSWORD", 
MONGODB_ROOT_PASSWORD)
+                    
.withCopyFileToContainer(forClasspathResource("/mongodb/mongo-init.js"),
+                            "/docker-entrypoint-initdb.d/mongo-init.js")
+                    .withLogConsumer(new 
Slf4jLogConsumer(LOG).withPrefix("basicAuthContainer"))
+                    .waitingFor(Wait.forLogMessage(".*Waiting for 
connections.*", 2));
+
+            container.start();
+
+            String authority = container.getHost() + ":" + 
container.getMappedPort(MONGODB_PORT).toString();
+            String connectionString = String.format("mongodb://%s", authority);
+
+            Map<String, String> config = new HashMap<>();
+            config.put("quarkus.mongodb.hosts", authority);
+            config.put("quarkus.mongodb.credentials.username", 
MONGODB_ROOT_USERNAME);
+            config.put("quarkus.mongodb.credentials.password", 
MONGODB_ROOT_PASSWORD);
+            config.put("quarkus.mongodb.myMongoClient.connection-string", 
connectionString);
+
+            return config;
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Override
+    public void stop() {
+        try {
+            if (container != null) {
+                container.stop();
+            }
+        } catch (Exception e) {
+            LOG.warn("An exception occurred while stopping the MongoDB 
container", e);
+        }
+    }
+}
diff --git 
a/data-extract-langchain4j/src/test/java/org/acme/extraction/RouteTest.java 
b/data-extract-langchain4j/src/test/java/org/acme/extraction/RouteTest.java
index de8965a..17efd90 100644
--- a/data-extract-langchain4j/src/test/java/org/acme/extraction/RouteTest.java
+++ b/data-extract-langchain4j/src/test/java/org/acme/extraction/RouteTest.java
@@ -24,6 +24,7 @@ import static org.hamcrest.Matchers.not;
  * TODO: Write example instructions (with a section to update the wiremock 
mappings)
  */
 @WithTestResource(OllamaTestResource.class)
+@WithTestResource(MongoDbTestResource.class)
 @QuarkusTest
 public class RouteTest {
 
diff --git a/data-extract-langchain4j/src/test/resources/mongodb/mongo-init.js 
b/data-extract-langchain4j/src/test/resources/mongodb/mongo-init.js
new file mode 100644
index 0000000..721cc5a
--- /dev/null
+++ b/data-extract-langchain4j/src/test/resources/mongodb/mongo-init.js
@@ -0,0 +1,22 @@
+db = new Mongo().getDB("transcripts_db");
+
+db.createCollection('transcripts_collection',{
+    capped: true,
+    size: 1000000000,
+    max: 1000
+});
+
+db.transcripts_collection.insertMany([
+    {
+        id: 1,
+        text: "Sample of text for item with id 1",
+    },
+    {
+        id: 2,
+        text: "Sample of text for item with id 2",
+    },
+    {
+        id: 3,
+        text: "Sample of text for item with id 3",
+    }
+]);

Reply via email to