Kafka Demo
· 1 min
javaspring-bootkafkadocker
A Spring Boot producer and consumer for Apache Kafka in one Maven build, with a Kafka broker and Kafka UI in the same Compose file. It replaces my two earlier repositories, kafkaproducer and kafkaconsumer.
What is inside?
- producer (port 8787):
POST /messageandPOST /messagespublish a JSON event keyed by its id, and wait for Kafka's answer. - consumer (port 8788): listens to the topic;
GET /messagesandGET /messages/dead-lettersshow what arrived. - contract: the
MessageEventrecord both sides share. - A dead letter topic,
demo.messages-dlt. Broken JSON or an empty text goes there right away, other failures after two more attempts, so one bad record never blocks the partition. - Kafka 4.4 in KRaft mode (no ZooKeeper) and Kafka UI on port 8085.
docker compose up --build
curl -X POST -H 'Content-Type: text/plain' --data 'Merhaba Kafka' localhost:8787/message
curl localhost:8788/messages
The whole walk-through is in the post Kafka on Your Laptop.
Source code: github.com/ergulcu/kafka-demo