How to view kafka message?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Viewing Kafka messages sounds simple, but the right method depends on what you are trying to inspect. A quick smoke test, a forensic lookup by offset, and a structured inspection of keys and headers are slightly different tasks.
The Simplest Option: Console Consumer
The built-in console consumer is the fastest way to see message values:
This prints message values from the start of the retained topic data. If you omit --from-beginning, the consumer reads only new messages from the point it joins.
For day-to-day debugging, add useful output properties:
That gives you far more context than printing values alone.
Reading a Specific Partition or Offset
Sometimes "view the message" really means "show me what is at offset 12345 in partition 2". The console consumer is less convenient for that. A tool such as kcat is usually better:
That reads exactly one message starting from a known offset. It is extremely useful when correlating application logs with Kafka position metadata.
If your topic uses Avro, Protobuf, or JSON with schemas, viewing raw bytes may not be enough. In that case, use the serializer-aware tooling in your stack or a UI that knows how to decode messages.
Seeing More Than the Value
A Kafka record has several parts:
- topic
- partition
- offset
- key
- value
- timestamp
- headers
When debugging routing or compaction behavior, the key matters as much as the value. When debugging retries or trace propagation, headers matter too.
Programmatic inspection in Java gives you full access:
This is the right approach when you need custom filtering or deserialization logic.
GUI Tools
For repeated inspection, a UI can be more efficient than shell commands. Tools such as AKHQ, Conduktor, or similar Kafka browsers let you:
- search within messages
- inspect headers
- jump between partitions
- decode structured payloads
That is especially useful in shared environments where multiple engineers need to inspect the same topic safely.
Practical Constraints
You can only view retained messages. If retention has expired or compaction has removed older records, the message is gone from Kafka even if old offsets are referenced in logs.
You also need to know whether your consumer group settings are interfering with what you expect to see. Reusing an old group ID can make it look like the topic is empty because the group has already advanced past the offsets you wanted.
Common Pitfalls
The most common mistake is consuming without --from-beginning and assuming the topic is empty. Often the consumer just started at the end.
Another issue is ignoring keys, partitions, and offsets. Those fields are often the only way to diagnose ordering, replay, or partitioning problems.
Teams also forget that raw console output may be serialized data, not readable business objects. If the topic uses Avro or Protobuf, use the appropriate decoder.
Finally, do not debug production traffic with a tool that commits offsets unintentionally unless you understand the impact on consumer groups.
Summary
- Use
kafka-console-consumer.shfor quick message viewing. - Use output properties to print keys, offsets, partitions, and timestamps.
- Use
kcatwhen you need precise control over partition and offset. - Use programmatic consumers or UIs when you need decoding, filtering, or header inspection.
- Always consider retention, serializer format, and consumer-group position when messages seem to be missing.

