jamesnetherton commented on code in PR #210:
URL: 
https://github.com/apache/camel-quarkus-examples/pull/210#discussion_r1575971087


##########
artemis-elasticsearch/README.adoc:
##########
@@ -0,0 +1,95 @@
+= Artemis to ElasticSearch
+:cq-example-description: An example that shows how the message is consumed 
from the Apache Artemis broker using MQTT protocol, transformed and loaded into 
ElasticSearch
+
+{cq-description}
+
+This example shows how to connect ActiveMQ Broker to Elasticsearch service, 
create index and send data to it.
+
+TIP: Check the 
https://camel.apache.org/camel-quarkus/latest/first-steps.html[Camel Quarkus 
User guide] for prerequisites
+and other general information.
+
+== Prerequisites:
+
+In order to send a message from Artemis Broker to Elasticsearch you need to 
start two services:
+
+1) ActiveMQ Artemis - message broker that is connected to a paho client.
+
+2) Elasticsearch - database that stores your data.
+
+You can also use docker instead of podman for all the steps below.
+
+
+== Create network for Elasticsearch:
+
+[source,shell]
+----
+podman network create elastic

Review Comment:
   Can we stick to `docker` instead of podman. It's more consistent with the 
other examples.



##########
artemis-elasticsearch/src/test/java/org/acme/ElasticSearchTest.java:
##########
@@ -0,0 +1,35 @@
+/*
+ * 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;
+
+import io.quarkus.test.common.QuarkusTestResource;
+import io.quarkus.test.junit.QuarkusTest;
+import org.acme.resource.CustomPahoTestResource;
+import org.acme.resource.ElasticSearchTestResource;
+import org.junit.jupiter.api.Test;
+
+@QuarkusTest
+@QuarkusTestResource(CustomPahoTestResource.class)
+@QuarkusTestResource(ElasticSearchTestResource.class)
+public class ElasticSearchTest {
+
+    @Test
+    public void baseTest() {

Review Comment:
   Should probably add a basic test case.



##########
artemis-elasticsearch/pom.xml:
##########
@@ -0,0 +1,325 @@
+<?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>
+
+    <artifactId>camel-quarkus-examples-artemis-elasticsearch</artifactId>
+    <groupId>org.apache.camel.quarkus.examples</groupId>
+    <version>3.9.0</version>
+
+    <name>Camel Quarkus :: Examples :: Artemis ElasticSearch</name>
+    <description>Camel Quarkus Example :: Artemis ElasticSearch</description>
+
+    <properties>
+        <quarkus.platform.version>3.9.1</quarkus.platform.version>
+        
<camel-quarkus.platform.version>${quarkus.platform.version}</camel-quarkus.platform.version>
+
+        
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
+        
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
+        
<camel-quarkus.platform.group-id>${quarkus.platform.group-id}</camel-quarkus.platform.group-id>
+        
<camel-quarkus.platform.artifact-id>quarkus-camel-bom</camel-quarkus.platform.artifact-id>
+
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+        <maven.compiler.target>17</maven.compiler.target>
+        <maven.compiler.source>17</maven.compiler.source>
+        
<maven.compiler.testTarget>${maven.compiler.target}</maven.compiler.testTarget>
+        
<maven.compiler.testSource>${maven.compiler.source}</maven.compiler.testSource>
+
+        <formatter-maven-plugin.version>2.23.0</formatter-maven-plugin.version>
+        <groovy-maven-plugin.version>2.1.1</groovy-maven-plugin.version>
+        <impsort-maven-plugin.version>1.9.0</impsort-maven-plugin.version>
+        <license-maven-plugin.version>4.2</license-maven-plugin.version>
+        <maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
+        <maven-jar-plugin.version>3.3.0</maven-jar-plugin.version>
+        <maven-resources-plugin.version>3.3.1</maven-resources-plugin.version>
+        <maven-surefire-plugin.version>3.1.2</maven-surefire-plugin.version>
+
+        <quarkus-artemis-jms.version>3.1.1</quarkus-artemis-jms.version>
+    </properties>
+
+    <dependencyManagement>
+        <dependencies>
+            <!-- Import BOM -->
+            <dependency>
+                <groupId>${quarkus.platform.group-id}</groupId>
+                <artifactId>${quarkus.platform.artifact-id}</artifactId>
+                <version>${quarkus.platform.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+            <dependency>
+                <groupId>${camel-quarkus.platform.group-id}</groupId>
+                <artifactId>${camel-quarkus.platform.artifact-id}</artifactId>
+                <version>${camel-quarkus.platform.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <dependencies>
+
+        <!-- Camel Quarkus -->
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-bean</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-direct</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-jackson</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-log</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-timer</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-paho</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-elasticsearch-rest-client</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-databind</artifactId>

Review Comment:
   We can remove `jackson-databind` as it's already a transitive of 
`camel-quarkus-jackson`.



##########
artemis-elasticsearch/src/test/java/org/acme/resource/CustomPahoTestResource.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.resource;
+
+import java.util.Map;
+
+import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.utility.DockerImageName;
+
+public class CustomPahoTestResource implements 
QuarkusTestResourceLifecycleManager {
+    private static final String IMAGE_NAME = 
"quay.io/artemiscloud/activemq-artemis-broker:latest";

Review Comment:
   Best avoid `latest` and pin to a fixed tag.



##########
artemis-elasticsearch/src/main/java/org/acme/Routes.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.http.entity.ContentType;
+
+public class Routes extends RouteBuilder {
+
+    public void process(Exchange exchange) throws IOException {
+        Map<String, String> map = new HashMap<>();
+
+        //get message from pojo class
+        String body = exchange.getMessage().getBody(String.class);
+        map.put("devices", body);
+
+        //convert map to json string
+        String jsonString = new ObjectMapper().writeValueAsString(map);

Review Comment:
   I think we can simplify this a bit. Creating a new `ObjectMapper` on each 
exchange is quite expensive.
   
   We should be able to use camel-jackson to convert the message payload to a 
JSON string. IIRC it will also set the `Content-Type` exchange header for you 
too.



##########
artemis-elasticsearch/src/test/java/org/acme/resource/CustomPahoTestResource.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.resource;
+
+import java.util.Map;
+
+import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.utility.DockerImageName;
+
+public class CustomPahoTestResource implements 
QuarkusTestResourceLifecycleManager {
+    private static final String IMAGE_NAME = 
"quay.io/artemiscloud/activemq-artemis-broker:latest";
+    private static final String AMQ_USER = "admin";
+    private static final String AMQ_PASSWORD = "admin";
+    private static final String AMQ_JOLOKIA = "--relax-jolokia";
+    private GenericContainer<?> container;
+
+    @Override
+    public Map<String, String> start() {
+        container = new GenericContainer<>(DockerImageName.parse(IMAGE_NAME))
+                .withExposedPorts(61616, 1883, 8161)
+                .withEnv("AMQ_USER", AMQ_USER)
+                .withEnv("AMQ_PASSWORD", AMQ_PASSWORD)
+                .withEnv("AMQ_EXTRA_ARGS", AMQ_JOLOKIA);
+
+        container.start();
+
+        return Map.of(
+                "camel.component.paho.brokerUrl",
+                "tcp://" + container.getHost() + ":" + 
container.getMappedPort(1883));
+
+    }
+
+    @Override
+    public void stop() {
+

Review Comment:
   Should probably stop the container here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@camel.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to