How to view a message in Kafka? - Big Data In Real World

How to view a message in Kafka?

What is the difference between map and mapValues functions in Spark?
April 13, 2023
How to rename an S3 bucket?
April 20, 2023
What is the difference between map and mapValues functions in Spark?
April 13, 2023
How to rename an S3 bucket?
April 20, 2023

Sometimes we have the need to see the message that we ingest into Kafka. This is typically needed for a quick sanity check or we recently made a change to the schema of the message and we want to make sure the change took effect properly.

In this post we will describe how to see messages that are ingested into a Kafka topic.

Kafka-console-consumer

Kafka out of the box comes with a handy script named kafka-console-consumer.sh. The script will read the messages from a topic and will print the messages on the screen.

The script, at the very least takes 3 inputs-

bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning

--bootstrap-server - to connect to Kafka brokers
--topic - name of the Kafka topic
–-from-beginning - indicates that we would like to read messages from the very beginning

Read from specific offset and partition

If we would like to read messages from a specific offset and from a very specific partition, then we should specify offset and partition values in the command like below.

bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test –partition 1 –offset 10

Limiting number of messages

Use the –max-messages flag to limit the number of maximum messages we would like to read.

bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test –partition 1 –offset 10 –max-messages 150
Big Data In Real World
Big Data In Real World
We are a group of Big Data engineers who are passionate about Big Data and related Big Data technologies. We have designed, developed, deployed and maintained Big Data applications ranging from batch to real time streaming big data platforms. We have seen a wide range of real world big data problems, implemented some innovative and complex (or simple, depending on how you look at it) solutions.

Comments are closed.

How to view a message in Kafka?
This website uses cookies to improve your experience. By using this website you agree to our Data Protection Policy.

Hadoop In Real World is now Big Data In Real World!

X