Skip to main content
dbains
Gold ⭐️
Gold ⭐️
Jun 29, 2017 2:35 PM UTC

How to view the oldest message in a Kafka topic?

  • Oct 5, 2026 9:09 AM UTC
  • 1 reply
  • 43241 views
  • Translate All

In a non-Kerberized environment, for Kafka console consumer command displays all messages, perform the following:

Note:
Here, <broker_host> is Kafka broker hostname, <zk_host> is zookeeper hostname and Kafka port will be 6667:
  1. Using Old consumer API (prior to HDP 2.5.x), run the following:

    bin/kafka-console-consumer.sh --zookeeper <zk_host>:2181 --topic test --from-beginning

  2. Using New consumer API ( From HDP 2.5.x onwards), run the following:

    bin/kafka-console-consumer.sh --bootstrap-server <broker_host>:6667 --topic test --from-beginnin

To view a specific number of message in a Kafka topic, use the --max-messages option. To view the oldest message, run the console consumer with --from-beginning and --max-messages 1:

  1. Using Old consumer API ( Prior to HDP 2.5.x):

    bin/kafka-console-consumer.sh --zookeeper <zk_host>:2181 --topic test --from-beginning
    --max-messages 1

  2. Using New consumer API ( From HDP 2.5.x onwards):

    bin/kafka-console-consumer.sh --bootstrap-server <broker_host>:6667 --topic test --from-beginning
    --max-messages

1 reply

erkansirin78
Gold ⭐️
Jun 12, 2018 9:01 PM UTC

Using the ConsoleConsumer with old consumer is deprecated and will be removed in a future major release. Consider using the new consumer by passing [bootstrap-server] instead of [zookeeper].

@dbains you should update

Translate