Coffee Shop Demo with Quarkus
This directory contains a set of demo around reactive in Quarkus with Kafka. It demonstrates the elasticity and resilience of the system.
Build
Install java dependencies (java 17 and Maven are required)
mvn clean package
Install node.js dependencies (node.js is required)
cd barista-node-kafka/ && npm install
Prerequisites
Install Docker.
Run the demo
You need to run:
- the coffee shop service
- one or more of the HTTP, Quarkus Kafka or Node.js Kafka baristas
In 3 or more terminals:
cd coffeeshop-service
mvn quarkus:dev
This also starts the Kafka Dev Service and create the orders
topic with 4 partitions.
HTTP barista
cd barista-quarkus-http
java -jar target/quarkus-app/quarkus-run.jar
Quarkus Barista
cd barista-quarkus-kafka
mvn quarkus:dev
Node.js Barista
cd barista-node-kafka
npm start
Execute with HTTP
The first part of the demo shows HTTP interactions:
- Barista code:
me.escoffier.quarkus.coffeeshop.BaristaResource
- CoffeeShop code:
me.escoffier.quarkus.coffeeshop.CoffeeShopResource#http
- Generated client:
me.escoffier.quarkus.coffeeshop.http.BaristaService
Order coffees by opening http://localhost:8080
. Select the HTTP method.
Stop the HTTP Barista, you can't order coffee anymore.
Execute with Kafka
-
Barista code:
me.escoffier.quarkus.coffeeshop.KafkaBarista
: Read fromorders
, write toqueue
-
Bridge in the CoffeeShop:
me.escoffier.quarkus.coffeeshop.messaging.CoffeeShopResource#messaging
just enqueue the orders in a single thread (one counter) -
Get prepared beverages on
me.escoffier.quarkus.coffeeshop.dashboard.BoardResource
and send to SSE -
Open browser to http://localhost:8080/
-
Order coffee with Order coffees by opening
http://localhost:8080
. Select the messaging method.
Baristas do breaks
- Stop the Kafka barista(s)
- Continue to enqueue order
- On the dashboard, the orders are in the "IN QUEUE" state
- Restart the barista
- They are processed
2 or more baristas are better
Quarkus
- Build
barista-quarkus-kafka
with native image:mvn package -Pnative
- Start a second barista with:
./barista-quarkus-kafka/target/barista-kafka-1.0-SNAPSHOT-runner -Dquarkus.http.port=9999
- Order more coffee
Node.js
- Open a new terminal and run
npm start
again.
The dashboard shows that the load is dispatched among the baristas.