What Is kafka-console-consumer.sh?
A beginner-friendly guide to the small command-line tool that lets you peek directly into a Kafka topic, without writing a single line of application code.
Imagine a large shipping warehouse with an enormous conveyor system moving packages around all day. As an engineer maintaining that warehouse, you would not want to build a whole new scanning application every single time you just wanted to peek at what was currently moving past a particular point on the belt. You would want a simple handheld scanner you could point at the belt and immediately see what is there. For anyone working with Kafka, that simple handheld scanner is a small command-line tool called kafka-console-consumer.sh. In this guide we will build up the whole picture slowly, defining every new word the first time it appears.
1Why a Simple Peeking Tool Is Genuinely Useful
Before defining the tool precisely, it helps to see the everyday need it fills.
Sometimes you just want to look
A consumer is any program that reads events from a Kafka topic, a named stream of related events. Building a full consumer application, with its own code, configuration, and deployment process, is exactly the right approach for a real, ongoing piece of business logic. But it is a lot of unnecessary effort just to answer a quick question like “is any data actually flowing into this topic right now” or “what does a typical event in this topic actually look like”.
This is a situation almost every engineer working with Kafka runs into constantly, especially while learning, testing, or troubleshooting. Writing and running a custom application every single time would slow everyone down considerably.
Think of a plumber checking whether water is flowing through a pipe. They do not build a custom measuring device for every single job; they simply hold a basic gauge up to the pipe for a quick, immediate answer. A console consumer plays exactly this role for a Kafka topic.
A tool built specifically for this everyday need
Kafka ships with a small collection of command-line tools specifically for tasks like this, and kafka-console-consumer.sh is the one built for quickly reading and displaying events from a topic directly in a terminal window, the text-based interface many engineers use to run commands on a computer.
2So, What Exactly Is kafka-console-consumer.sh?
A precise definition, then the plain-English version.
A short definition
kafka-console-consumer.sh is a command-line script included with Apache Kafka that acts as a simple, ready-made consumer, connecting to a Kafka cluster, reading events from a chosen topic, and printing them out directly to your terminal window as plain text, one after another, as they are read.
In everyday terms, it is a small, disposable consumer you can start up in seconds, watch for as long as you like, and shut down the moment you have seen what you needed to see, without writing, compiling, or deploying any application code at all.
Why the name looks the way it does
The name breaks down quite literally. “Kafka” identifies which system this tool belongs to. “Console” refers to the terminal, or console, where its output appears. “Consumer” describes exactly what it does, consuming, meaning reading, events from a topic. The “.sh” ending simply indicates it is a shell script, a small program written to be run directly from a command-line terminal.
This tool is generally found inside Kafka’s own installation folder, in a directory commonly named “bin”, alongside several other similarly named command-line tools for tasks like producing events or managing topics.
3The Two Pieces of Information It Always Needs
Before it can do anything useful, this tool needs to know two basic things.
Which cluster to connect to
The tool needs to know the network address of at least one broker, a Kafka server, so it knows where to actually find the cluster it should read from.
Which topic to read
The tool needs the exact name of the topic whose events you want to watch, since a cluster typically holds many different topics at once.
Without these, it cannot do its job
Just like a delivery driver needs both an address and a specific parcel to deliver, this tool cannot meaningfully start without knowing exactly which cluster to talk to and exactly which topic within that cluster it should be watching. Every other option available on this tool builds on top of these two essential pieces of information.
Think of tuning an old radio. You need to know which station’s frequency to dial into before you can hear anything meaningful at all. The cluster address is roughly like knowing which radio station’s broadcast tower to point toward, and the topic name is like the specific frequency you dial in on that tower.
4Where Does Reading Actually Start From?
One of the very first practical choices you make when running this tool.
Only new events, by default
Without being told otherwise, kafka-console-consumer.sh generally only shows events published from the moment it starts running onward. Anything that was already sitting in the topic before you started watching will simply not appear, since the tool begins reading from the latest available point by default.
Choosing to see everything from the start
The tool also offers a setting to instead begin reading from the very earliest available event still retained in the topic, effectively showing you the topic’s full existing history, within whatever retention period, a setting controlling how long data is kept, that topic is currently configured with.
| Starting Point | What you see | Typical use |
|---|---|---|
| Latest (default) | Only events published from now onward | Watching live activity as it happens |
| Earliest | The topic’s full retained history, then live activity | Reviewing what has already happened in a topic |
Beginners often run this tool expecting to immediately see existing data in a busy topic, only to see nothing at all, simply because it defaulted to watching only for new events from that moment forward, rather than the topic’s past history.
5What Actually Gets Printed to the Screen
Understanding exactly what you are looking at once events start appearing.
The value, by default
By default, this tool typically prints just the value, the main content, of each event it reads, with each one shown on its own new line as it arrives, giving a simple, scrolling view of the topic’s activity over time.
Choosing to see the key as well
The tool also offers a setting to additionally print each event’s key, an identifying label often used for routing and grouping, alongside its value. This is especially useful when trying to understand how a topic’s data is actually organised, or when checking whether related events are sharing the same key as expected.
Example: Verifying a Key Is Set Correctly
An engineer suspecting that a producer is not attaching the expected customer identifier as a key might enable key display specifically to confirm, at a glance, whether the keys appearing alongside each event actually look correct.
This tool generally displays raw text as it reads it. If a topic’s values are stored in a binary or heavily structured format, the plain text shown on screen might look unfamiliar or only partially readable without some extra formatting help.
6Watching a Specific Partition, Not the Whole Topic
Sometimes you want a narrower, more focused view than the entire topic.
Focusing on just one slice
A topic is often split into smaller pieces called partitions, each an independently ordered slice of the topic’s overall data. This tool offers a setting to focus specifically on just one chosen partition, rather than reading across every partition of the topic at once.
Why you might want this
This narrower view can be especially useful while troubleshooting, such as when a team suspects a problem is affecting only certain events, and those events are known to always land on a particular partition because they share a specific key, an identifying label that consistently maps to that one partition.
Think of a supermarket with several checkout lanes. Watching the entire topic is like standing back and observing every lane at once, while focusing on a single partition is like standing directly behind just one specific lane, watching only what passes through that one line.
7Stopping After a Fixed Number of Events
A small but genuinely handy setting for quick, one-off checks.
Watching indefinitely, by default
Left to its own devices, this tool will keep running and printing new events indefinitely, until the person running it manually stops it, typically by pressing a specific interrupt key combination in the terminal.
Setting a limit instead
The tool also offers a setting to automatically stop itself after printing a specific number of events, which is especially convenient for a quick sanity check, such as confirming that a handful of recent events look roughly as expected, without needing to watch and manually stop it yourself.
Example: A Quick Sanity Check
An engineer who just deployed a new producer might run the console consumer with a limit of five events, quickly confirming that the newest data looks correct, then let the tool exit on its own, without needing to babysit an indefinitely running terminal window.
8Does Using This Tool Count as a Real Consumer Group?
An important, practical question with a slightly nuanced answer.
By default, a temporary, throwaway identity
A consumer group is a named team of consumers sharing the work of reading a topic, with its reading progress durably tracked. Unless told otherwise, this tool typically connects using a randomly generated, temporary consumer group identity each time it runs, meaning it does not meaningfully build up any lasting, durable reading progress you would rely on later.
Explicitly joining a named group
The tool also allows you to specify an actual, named consumer group if desired, causing it to behave much more like a genuine, ongoing consumer, tracking and committing its offsets, numbers marking its exact reading position, just as a real application consumer would.
Running this tool repeatedly under the exact same named consumer group can interfere with a real, ongoing application relying on that same group’s tracked progress. It is generally safer to use a throwaway, unnamed run, or a clearly distinct group name, purely for casual inspection.
9How This Tool Fits Alongside Its Companion Tools
This tool rarely works entirely alone; it usually has a natural counterpart.
The producer side of the same idea
Kafka also ships with a companion tool, commonly named kafka-console-producer.sh, which lets an engineer type text directly into a terminal and publish it as events into a chosen topic. Together, these two simple tools let someone quickly send a test event with one tool and immediately watch it arrive with the other, entirely from the command line.
Tools for managing topics themselves
Kafka additionally provides other command-line tools focused on managing topics directly, such as creating a new topic, listing existing ones, or inspecting a topic’s current configuration and partition details, rounding out a small but genuinely useful toolkit for everyday, hands-on Kafka work.
flowchart LR
Prod["kafka-console-producer.sh"] -->|publishes test event| Topic[Kafka Topic]
Topic -->|read live| Cons["kafka-console-consumer.sh"]
10Advantages and Trade-offs
A genuinely handy tool, but not without its limits.
Advantages
- Ships with Kafka, requiring no separate installation or setup
- Lets anyone peek into a topic within seconds, with no coding required
- Extremely useful for quick learning, testing, and troubleshooting
- Simple, familiar starting-point and stopping settings cover most quick checks
Disadvantages / Trade-offs
- Not meant for real, ongoing application logic or business processing
- Displays raw text, which can look unfamiliar for structured or binary data without extra help
- Careless use of a shared, named consumer group can interfere with real applications
- Offers only a narrow slice of what a fully built consumer application can do
11Real-World Situations Where This Tool Shines
Seeing a few concrete examples brings the whole idea to life.
Verifying a New Producer Is Working
After deploying a brand-new producer, an engineer can quickly confirm events are actually arriving in the expected topic, with the expected shape, before trusting it further.
Learning Kafka for the First Time
A newcomer experimenting with topics, keys, and partitions can immediately see the real, tangible effect of their actions, without first needing to learn how to write a full consumer application.
Diagnosing a Silent Consumer
If a real application consumer appears to be stuck or receiving nothing, checking the topic directly with this tool helps quickly confirm whether the problem lies with the topic itself or with that specific application.
Demonstrating Kafka in a Meeting or Training Session
A presenter can visibly show events flowing through a topic in real time, making an otherwise abstract concept feel immediate and concrete for an audience.
12Best Practices and Common Mistakes
Practical lessons for using this tool comfortably and safely.
Best practices
Remember it is for inspection, not production logic
Treat it purely as a quick, temporary window into a topic, never as a replacement for a properly built application consumer.
Choose the right starting point deliberately
Decide whether you actually want existing history or only new, live activity before you start, to avoid confusing, seemingly empty results.
Avoid reusing a real application’s consumer group
Use a distinct, clearly temporary identity when inspecting a topic, so you never accidentally disturb a genuine, ongoing consumer’s tracked progress.
Use limits for quick, one-off checks
Set a fixed number of events to display when you only need a quick glance, rather than manually starting and stopping an indefinitely running session.
Pair it with the console producer for quick experiments
Use both tools together to quickly test how new data appears in a topic, especially while learning or troubleshooting.
Mistakes beginners often make
Forgetting that the tool watches only for new events by default often leads to confusion when nothing appears to be happening in what is actually a perfectly active topic.
Relying on this tool for anything resembling genuine business processing overlooks the fact that it was never designed for that purpose, and lacks the structure a real consumer application would provide.
Running this tool under the exact same consumer group name as a production application can shift that application’s tracked reading progress unexpectedly, causing confusing, hard-to-diagnose behaviour.
13Frequently Asked Questions
No. It is a ready-made command-line tool. You simply provide it with the cluster address and the topic name you want to watch, along with any optional settings you choose.
By default, the tool only shows events published from the moment it starts onward. To see a topic’s existing history, you need to explicitly choose to start reading from the earliest available point instead.
Generally, yes, since reading a topic does not remove or change its data. The main caution is around consumer group usage, avoiding reusing a real application’s named group to prevent interfering with its tracked progress.
Yes. The tool offers a setting to display each event’s key alongside its value, which is useful for confirming how data is grouped or routed within a topic.
Since it runs indefinitely by default, it is typically stopped manually using a standard terminal interrupt key combination, or automatically if a maximum number of events to display has been configured in advance.
Yes. A setting lets you focus on a single chosen partition, rather than reading across an entire topic’s partitions at once, which is useful for narrower, more focused troubleshooting.
Yes. A companion tool, commonly named kafka-console-producer.sh, lets you type text directly into a terminal and publish it as events, making it easy to pair with the console consumer for quick, hands-on experiments.
14Summary and Key Takeaways
kafka-console-consumer.sh is a small, ready-made command-line tool, shipped directly with Kafka, that lets anyone quickly connect to a cluster, read events from a chosen topic, and see them printed right in their terminal, all without writing or deploying any application code. With just a cluster address and a topic name as its essential starting point, it offers a handful of genuinely useful settings, choosing where reading starts, whether keys are shown, which partition to focus on, and when to automatically stop, that together make it a natural first stop for learning, testing, and troubleshooting Kafka topics. While it is never meant to replace a properly built consumer application, its simplicity and immediacy make it one of the most frequently reached-for tools in everyday, hands-on Kafka work.
Key Takeaways
- It is a ready-made, disposable consumer — no application code needed, just run it from the command line.
- It needs a cluster address and a topic name — the two essential pieces of information it cannot start without.
- It watches only new events by default — choosing to start from the earliest offset instead shows a topic’s existing history.
- It can show keys, focus on one partition, or stop after a limit — small settings that make quick, targeted checks easy.
- Its consumer group usage deserves care — avoid reusing a real application’s group to prevent interfering with its progress.
- It pairs naturally with a console producer — together enabling quick, end-to-end, hands-on experiments.
- It is for inspection, not production logic — a lightweight window into a topic, never a substitute for real application code.