This repository demonstrates how to transform a Spring Boot Kafka application to native executable using GraalVM.
- Docker
./gradlew bootBuildImage*** Occasionally You may see the following error: Error: Image building with exit status 137.This error occurs if the
system runs out of ram, in order to fix this increase Docker memory e.g 10GB
cd docker
docker compose up -ddocker compose ps
# NAME SERVICE STATUS PORTS
# akhq akhq running 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp
# kafka kafka running 0.0.0.0:9092->9092/tcp, :::9092->9092/tcp, 0.0.0.0:9101->9101/tcp, :::9101->9101/tcp
# schema-registry schema-registry running 0.0.0.0:8081->8081/tcp, :::8081->8081/tcp
# spring-native-demo spring-native-demo running 0.0.0.0:7777->7777/tcp, :::7777->7777/tcp
# zookeeper zookeeper running 0.0.0.0:2181->2181/tcp, :::2181->2181/tcp, 2888/tcp, 3888/tcpdocker compose logs -f spring-native-demo
# spring-native-demo | 2021-07-07 17:46:28.155 INFO 1 --- [ scheduling-1] c.r.app.customers.RandomEventGenerator : Successfully sent CustomerCreated event {"eid": "5178e6bf-c241-45bc-9e1b-90a789ec328c", "userId": "9958e080-bafc-4f84-b4c0-f1ee180a3db3", "email": "2a22ea77-6187-4860-98de-a14a549ab06a@test.com", "name": "Name adb925cc-aa8e-4be1-be21-7f71c0d0aa0a"}
# spring-native-demo | 2021-07-07 17:46:28.158 INFO 1 --- [-StreamThread-1] c.r.app.customers.CustomerEventsKStream : Consumed customer event {"eid": "5178e6bf-c241-45bc-9e1b-90a789ec328c", "userId": "9958e080-bafc-4f84-b4c0-f1ee180a3db3", "email": "2a22ea77-6187-4860-98de-a14a549ab06a@test.com", "name": "Name adb925cc-aa8e-4be1-be21-7f71c0d0aa0a"}.
# spring-native-demo | 2021-07-07 17:46:28.158 INFO 1 --- [ntainer#0-0-C-1] c.r.app.customers.CustomerEventListener : Received CustomerCreated event -> {"eid": "5178e6bf-c241-45bc-9e1b-90a789ec328c", "userId": "9958e080-bafc-4f84-b4c0-f1ee180a3db3", "email": "2a22ea77-6187-4860-98de-a14a549ab06a@test.com", "name": "Name adb925cc-aa8e-4be1-be21-7f71c0d0aa0a"}docker compose stop spring-native-demodocker compose start spring-native-demodocker compose logs spring-native-demo | grep "Started NativeApplication"
# spring-native-demo | 2021-07-07 18:02:34.108 INFO 1 --- [ main] com.rbiedrawa.app.NativeApplication : Started NativeApplication in 0.152 seconds (JVM running for 0.156)
# spring-native-demo | 2021-07-07 18:03:35.373 INFO 1 --- [ main] com.rbiedrawa.app.NativeApplication : Started NativeApplication in 0.127 seconds (JVM running for 0.13)When you're done, stop Docker containers by running.
docker compose down -v| Name | Endpoint |
|---|---|
Akhq UI |
http://localhost:8080/ |
Schema-registry |
http://localhost:8081/ |
For further reference, please consider the following sections:
- Spring Native Reference Guide
- Configure the Spring AOT Plugin
- Announcing Spring Native Beta!
- Spring for Apache Kafka
- Kafka Docker Images
- I tried Spring Native for GraalVM and I like it!
Distributed under the MIT License. See LICENSE for more information.