This is an example Micronaut microservice application built as a POC/exercise for me to get to know the framework. It features:
- REST endpoint that accepts a topic and message as input and produces that message on the given topic
- Kafka consumer that listens to all topics on the given cluster
- embedded kafka integration test
- kafka integration test using Testcontainers
- Openapi docs published at http://localhost:8080/swagger/kafka-rest-app-0.0.yml
- swagger-ui views published at http://localhost:8080/swagger-ui/
- rapidoc views published at http://localhost:8080/rapidoc/
- prometheus metrics published to http://localhost:8080/prometheus
- leverage Micronaut's (jib) ability to build a docker image
- run as a native image with GraalVM
For development with hot reloading
- start the required services in the background
docker-compose up -d zookeeper kafka-cluster kafka-ui
- run the application
./mvnw mn:run
To run the application in a docker container:
- build/install the local docker image
./mvnw clean package -Dpackaging=docker
- Run with
docker-compose
docker-compose up
Prerequisite: Install the GraalVM. The easiest way to do this is with sdkman.
sdk install java 21.0.0.r11-grl
gu install native-image
- Build the native image
./mvnw clean package -Dpackaging=native-image
- Start the docker dependencies
docker-compose up -d zookeeper kafka-cluster kafka-ui
- Run the native binary
target/kafka-rest-app
- Build the native docker container
./mvnw clean package -Dpackaging=docker-native
- Run with docker-compose
docker-compose up
- Java 11 (optional -> GraalVM)
- Docker