Issue
I'm using Kafka console consumer to consume messages from the topic with several partitions:
kafka-console-consumer.bat --bootstrap-server localhost:9092 --from-beginning --topic events
But it prints only message body. Is there any way to print record metadata or partition number as well? Cause I want to know where the message сonsumed from.
I've explored console consumer doc http://documentation.kamanja.org/_static/command-ref/kafka-console-consumer.pdf but didn't find any related properties.
UPDATED:
So, as I see the only solution is to override DefaultMessageFormatter.class (we can set it by running kafka console consumer with --formatter property) and add custom logic that prints record metadata in the #writeTo(..) method.
Solution
Consider using a more powerful Kafka command line consumer like kafkacat https://github.com/edenhill/kafkacat/blob/master/README.md
For example, the following command will print the topic, partition, offset and message payload/value for each message consumed:
kcat -b <broker> -C -t <topic> -f '%t %p @ %o: %s\n'
Answered By - Hans Jespersen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.