This project illustrates how you can interact with Apache Kafka using MicroProfile Reactive Messaging and Hibernate with Panache. The project uses:
- RESTEasy Reactive
- Reactive Messaging and its connector for Kafka
- Hibernate Reactive with Panache
NOTE: The kafka-panache-quickstart provides the same example but using classic Hibernate.
Start the application in dev mode with:
mvn quarkus:dev
NOTE: Quarkus Dev Services starts the database and Kafka broker automatically.
Then, open your browser to http://localhost:8080/prices
, and you should get the set of prices written in the database.
Every 5 seconds, a new price is generated, sent to a Kafka topic, received by a Kafka consumer, and written to the database.
Refresh the page to see more prices.
PriceGenerator
- a bean generating random price. They are sent to a Kafka topic.PriceStorage
- on the consuming side, thePriceStorage
receives the Kafka message and write it into the database using Hibernate with PanachePriceResource
- thePriceResource
retrieves the prices from the database and send them into the HTTP response
You can compile the application into a native binary using:
mvn clean install -Pnative
As you are not in dev or test mode, you need to start a PostgreSQL instance and a Kafka broker.
To start them, just run docker-compose up -d
.
Then, run the application with:
./target/kafka-panache-reactive-quickstart-1.0.0-SNAPSHOT-runner