This project illustrates how Quarkus applications can interact with Apache Kafka using MicroProfile Reactive Messaging.
The application is composed of two applications communicating through Kafka. Interactions with Kafka is managed by MicroProfile Reactive Messaging.
They can be started in dev mode using:
mvn -f producer quarkus:devand in another terminal:
mvn -f processor quarkus:devNOTE: Quarkus Dev Services starts a Kafka broker for you automatically.
Then, open your browser at http://localhost:8080/quotes.html.
You can send quote requests and observe received quotes.
The application is composed of the following components:
The producer application receive requests from the user (via HTTP) and sends quote requests to the Kafka broker. Two main components compose the application:
QuoteProducergenerates uniquely identified quote requests and sends them to the Kafka topicquote-requests. It also consumes the Kafka topicquotesand relays received messages to the browser using Server-Sent Events.quotes.htmlsends quote requests to the previous endpoint and updates quotes with received prices.
The processor application receives quote requests from Kafka, processes them, and writes results into the quotes Kafka topic.
The application has one main class:
QuoteProcessorconsumes quote request ids from thequote-requestsKafka topic and responds back to thequotestopic with aQuoteobject containing a random price.
The connection to Kafka is configured in the src/main/resources/application.properties file.
To run the application in Docker, first make sure that both services are built:
mvn packageThen launch Docker Compose:
docker-compose upThis will create a single-node Kafka cluster and launch both applications.
You can compile the application into a native binary using:
mvn package -DnativeAs you are running in prod mode, you need a Kafka cluster.
If you have Docker installed, you can simply run:
export QUARKUS_MODE=native
docker-compose up --buildAlternatively, you can follow the instructions from the Apache Kafka web site.
Then run both applications respectively with:
./producer/target/kafka-quickstart-producer-1.0.0-SNAPSHOT-runnerand in another terminal:
./processor/target/kafka-quickstart-processor-1.0.0-SNAPSHOT-runner