Kafka console consumer get partition

MeetJoeBlack :

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.

Hans Jespersen :

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:

kafkacat -b <broker> -C -t <topic> -f '%t %p @ %o: %s\n'

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=464744&siteId=1