Duration: 30 mins
Uses the broker started in 01_kafka_docker.md.
Open a shell into the running container
docker exec -it kafka bash
All commands below run from inside the container, from /opt/kafka.
Create a topic orders with 3 partitions and a replication factor of 1 (single broker, so 1 is the only valid value)
bin/kafka-topics.sh --create --topic orders \
--bootstrap-server localhost:9092 \
--partitions 3 --replication-factor 1
List all topics and describe orders
bin/kafka-topics.sh --list --bootstrap-server localhost:9092
bin/kafka-topics.sh --describe --topic orders --bootstrap-server localhost:9092
Identify the leader, replicas and ISR for each partition (there’s only
one broker, so all three columns should point at broker 1).
Alter the topic’s retention to 10 minutes (600000 ms) using
--alter --config, then confirm the change with --describe
bin/kafka-topics.sh --alter --topic orders \
--bootstrap-server localhost:9092 \
--config retention.ms=600000
bin/kafka-topics.sh --describe --topic orders --bootstrap-server localhost:9092
Produce a few keyed messages with kafka-console-producer — use
key:value syntax so each key routes to a deterministic partition
bin/kafka-console-producer.sh --topic orders \
--bootstrap-server localhost:9092 \
--property "parse.key=true" --property "key.separator=:"
Send: order-1:first order, order-2:second order, order-1:third order
Consume from the beginning with kafka-console-consumer, printing keys
and the partition each record landed on
bin/kafka-console-consumer.sh --topic orders \
--bootstrap-server localhost:9092 --from-beginning \
--property print.key=true --property print.partition=true
Confirm both order-1 messages landed on the same partition (same key
→ same partition, as long as the partition count doesn’t change) while
order-2 likely landed elsewhere.
Delete the topic and confirm it’s gone
bin/kafka-topics.sh --delete --topic orders --bootstrap-server localhost:9092
bin/kafka-topics.sh --list --bootstrap-server localhost:9092