|
| 1 | += Artemis to ElasticSearch: A Camel Quarkus example |
| 2 | +: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 |
| 3 | + |
| 4 | +{cq-description} |
| 5 | + |
| 6 | +This example shows how to connect ActiveMQ Broker to Elasticsearch service, create index and send data to it. |
| 7 | + |
| 8 | +TIP: Check the https://camel.apache.org/camel-quarkus/latest/first-steps.html[Camel Quarkus User guide] for prerequisites |
| 9 | +and other general information. |
| 10 | + |
| 11 | +== Prerequisites: |
| 12 | + |
| 13 | +In order to send a message from Artemis Broker to Elasticsearch you need to start two services: |
| 14 | + |
| 15 | +1) ActiveMQ Artemis - message broker that is connected to a paho client. |
| 16 | + |
| 17 | +2) Elasticsearch - database that stores your data. |
| 18 | + |
| 19 | +You can also use podman instead of docker for all the steps below. |
| 20 | + |
| 21 | +== Run the containers: |
| 22 | + |
| 23 | +=== Run the Artemis container: |
| 24 | + |
| 25 | +[source,shell] |
| 26 | +---- |
| 27 | +docker run -d --rm -e AMQ_EXTRA_ARGS="--relax-jolokia" -e AMQ_USER=admin -e AMQ_PASSWORD=admin -p 61616:61616 -p 8161:8161 -p 1883:1883 --name artemis quay.io/artemiscloud/activemq-artemis-broker:1.0.26 |
| 28 | +---- |
| 29 | + |
| 30 | +Now you can access Artemis on localhost:8161 |
| 31 | + |
| 32 | +=== Run the Elasticsearch container: |
| 33 | + |
| 34 | +[source,shell] |
| 35 | +---- |
| 36 | +docker run -d --rm --name elasticsearch -p 9200:9200 -p 9300:9300 -it -m 4GB -e "discovery.type=single-node" -e "xpack.security.enabled=false" docker.io/elastic/elasticsearch:8.13.2 |
| 37 | +---- |
| 38 | + |
| 39 | +Now you can access Elasticsearch on localhost:9200 |
| 40 | + |
| 41 | + |
| 42 | +== Start in the Development mode |
| 43 | + |
| 44 | +[source,shell] |
| 45 | +---- |
| 46 | +mvn clean compile quarkus:dev |
| 47 | +---- |
| 48 | + |
| 49 | +== Package and run the application |
| 50 | + |
| 51 | +Once you are done with developing you may want to package and run the application. |
| 52 | + |
| 53 | +TIP: Find more details about the JVM mode and Native mode in the Package and run section of |
| 54 | +https://camel.apache.org/camel-quarkus/latest/first-steps.html#_package_and_run_the_application[Camel Quarkus User guide] |
| 55 | + |
| 56 | +=== JVM mode: |
| 57 | + |
| 58 | +[source,shell] |
| 59 | +---- |
| 60 | +mvn clean package |
| 61 | +java -jar target/quarkus-app/quarkus-run.jar |
| 62 | +---- |
| 63 | + |
| 64 | +=== Native mode |
| 65 | + |
| 66 | +IMPORTANT: Native mode requires having GraalVM and other tools installed. Please check the Prerequisites section |
| 67 | +of https://camel.apache.org/camel-quarkus/latest/first-steps.html#_prerequisites[Camel Quarkus User guide]. |
| 68 | + |
| 69 | +To prepare a native executable using GraalVM, run the following command: |
| 70 | + |
| 71 | +[source,shell] |
| 72 | +---- |
| 73 | +mvn clean package -Pnative |
| 74 | +./target/*-runner |
| 75 | +---- |
| 76 | + |
| 77 | +=== Send and retrieve messages: |
| 78 | + |
| 79 | +==== Send a message to the Artemis broker: |
| 80 | + |
| 81 | +---- |
| 82 | +curl -d 'my cool device' -H 'Content-Type: text/plain' localhost:8080/devices |
| 83 | +---- |
| 84 | + |
| 85 | +NOTE: You may need to wait a few seconds for the data to be persisted before it can be retrieved. |
| 86 | + |
| 87 | +==== Retrieve from Elasticsearch: |
| 88 | + |
| 89 | +---- |
| 90 | +curl localhost:8080/devices |
| 91 | +---- |
| 92 | + |
| 93 | +=== Stop the containers: |
| 94 | + |
| 95 | +---- |
| 96 | +docker stop elasticsearch |
| 97 | +docker stop artemis |
| 98 | +---- |
| 99 | + |
| 100 | +== Feedback |
| 101 | + |
| 102 | +Please report bugs and propose improvements via https://github.com/apache/camel-quarkus/issues[GitHub issues of Camel Quarkus] project. |
0 commit comments