Spring Boot app that produces news messages to Kafka. It runs in Native mode
1.4K
springboot-kafka-producer-native is a Java web application developed with Spring Boot, leveraging GraalVM Native Image to achieve native compilation. The source code for this project is available in the ivangfr/graalvm-quarkus-micronaut-springboot repository.
springboot-kafka-producer-native is the producer for the springboot.news.native Kafka topic. On the other hand, springboot-kafka-consumer-native is the consumer.
Ivan Franchin (LinkedIn) (Github) (Medium) (Twitter)
The application has the following endpoint:
KAFKA_HOST
Specify host of the Kafka message broker to use (default localhost)
KAFKA_PORT
Specify port of the Kafka message broker to use (default 29092)
Create network
docker network create springboot-producer-consumer-native-network
Start Zookeeper container
docker run -d --rm --name zookeeper \
-p 2181:2181 \
-e ZOOKEEPER_CLIENT_PORT=2181 \
--network springboot-producer-consumer-native-network \
confluentinc/cp-zookeeper:7.3.1
Start Kafka container
docker run -d --rm --name kafka \
-p 9092:9092 \
-e KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 \
-e KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT \
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092 \
-e KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1 \
--network springboot-producer-consumer-native-network \
confluentinc/cp-kafka:7.3.1
Start springboot-kafka-producer-native
docker run --rm --name springboot-kafka-producer-native \
-p 9080:8080 \
-e SPRING_PROFILES_ACTIVE=native \
-e KAFKA_HOST=kafka \
-e KAFKA_PORT=9092 \
--network springboot-producer-consumer-native-network \
ivanfranchin/springboot-kafka-producer-native:1.0.0
Start springboot-kafka-consumer-native
docker run --rm --name springboot-kafka-consumer-native \
-p 9081:8080 \
-e SPRING_PROFILES_ACTIVE=native \
-e KAFKA_HOST=kafka \
-e KAFKA_PORT=9092 \
--network springboot-producer-consumer-native-network \
ivanfranchin/springboot-kafka-consumer-native:1.0.0
To stop press
Ctrl+C
Make post news request
curl -i -X POST localhost:9080/api/news \
-H 'Content-Type: application/json' \
-d '{"source": "CNN", "title": "Palmeiras wins Copa Libertadores in 2021"}'
To stop press
Ctrl+C
Cleanup
docker stop kafka zookeeper
docker network rm springboot-producer-consumer-native-network
Content type
Image
Digest
sha256:80c205729…
Size
65 MB
Last updated
5 months ago
docker pull ivanfranchin/springboot-kafka-producer-native