Mehmet Ergülcü

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 /message and POST /messages publish a JSON event keyed by its id, and wait for Kafka's answer.
  • consumer (port 8788): listens to the topic; GET /messages and GET /messages/dead-letters show what arrived.
  • contract: the MessageEvent record 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

© 2026 Mehmet Ergülcü SvelteKit · Tailwind · <1 KB JS