Kafka from the Command Line
Get fluent with the Kafka command-line tools — create and inspect topics, produce and consume messages, track consumer-group lag, and tune topic configuration, all from the bundled kafka-*.sh scripts.
Every Kafka install ships with a set of small shell tools — kafka-topics.sh, kafka-console-producer.sh, kafka-console-consumer.sh, kafka-consumer-groups.sh, kafka-configs.sh. They are the fastest way to look inside a cluster, push a test message, or find out why a consumer is falling behind, and they are always there on the broker you just connected to. We start with an empty cluster and build real fluency one command at a time: creating a topic and reading its partition layout, producing JSON orders at an interactive prompt, consuming history versus only-new, tracking lag for a consumer group, and tuning retention. Each idea lands on its own command so nothing blurs together.
What you'll build
- Create, list, describe and delete topics
- Produce messages at the interactive console producer
- Consume from the beginning versus only new messages
- Use consumer groups and read their lag
- Tune topic configuration like retention
- Drive the tools non-interactively for scripts
Contents
- Create a topic
- List the topics
- Describe a topic
- Open the console producer
- Send a few messages
- Stop producing
- Read the topic from the start
- Read only new messages
- Print keys alongside values
- Take a fixed number of messages
- Consume as a group
- Describe the consumer group
- List the consumer groups
- Change a topic's retention
- Read the topic's config
- Add more partitions
- Confirm the new partitions
- Delete a topic
- The shape of every Kafka command