I can do this:
./bin/kafka-avro-console-consumer --zookeeper 10.0.0.225:2181/kafka --topic myTopic --property schema.registry.url=http://10.0.0.100:8081 --from-beginning
But I have too many messages. I would rather only get the last N ones. How can I do that with kafka console consumer?
Use -o -5 for last 5 messages, etc. Show activity on this post. With KafkaCat (https://docs.confluent.io/platform/current/app-development/kafkacat-usage.html) last N messages of an Apache Kafka Topic can be read.
If you want to process a topic from its beginning, you can simple start a new consumer group (i.e., choose an unused group.id ) and set auto. offset. reset = earliest . Because there are no committed offsets for a new group, auto offset reset will trigger and the topic will be consumed from its beginning.
Assuming that we want to consume the messages between offsets 11 and 21 , we need to run the following kafkacat command: -o 11 denotes that the consumer should start fetching messages from offset 11 , and -c 10 specifies that we only need to consume the first ten messages starting from offset 11 .
If you want to stick with the bundled binaries, you need to use the simple consumer shell:
bin/kafka-simple-consumer-shell.sh --broker-list mybroker:9092 --topic mytopic --partition mypartition --offset myoffset
I recommend kt; it's much faster, more lightweight and has better options.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With