【kafka】kafka topic Dump log

x33g5p2x  于2022-01-04 转载在 Kafka  
字(2.2k)|赞(0)|评价(0)|浏览(658)

1.概述

转载:https://www.cnblogs.com/foolaround/articles/14676070.html

有时,当我们使用 Kafka 时,可能会发现自己需要手动检查主题的底层日志。无论你只是好奇 Kafka 内部还是你需要调试一个问题并验证内容,kafka-dump-log 命令都是你的朋友。下面介绍如何使用这个命令,该示例的主题名为 example:

Copy

kafka-dump-log \
--print-data-log \ 
--files ./iteblog/kafka/data/example-0/00000000000000000000.log 

•--print-data-log 标记指定打印 log 里面的数据;
•--files 标记是必选项,可以是逗号分隔的文件列表。

如果想查看 kafka-dump-log 命令的所有支持的选项,可以使用 --help。运行上面的命令可以得到以下的输出:

Dumping ./var/lib/kafka/data/example-0/00000000000000000000.log
Starting offset: 0
baseOffset: 0 lastOffset: 0 count: 1 baseSequence: -1 lastSequence: -1 producerId: -1 producerEpoch: -1 partitionLeaderEpoch: 0 isTransactional: false isControl: false position: 0 CreateTime: 1599775774460 size: 81 magic: 2 compresscodec: NONE crc: 3162584294 isvalid: true
| offset: 0 CreateTime: 1599775774460 keysize: 3 valuesize: 10 sequence: -1 headerKeys: [] key: 887 payload: -2.1510235
baseOffset: 1 lastOffset: 9 count: 9 baseSequence: -1 lastSequence: -1 producerId: -1 producerEpoch: -1 partitionLeaderEpoch: 0 isTransactional: false isControl: false position: 81 CreateTime: 1599775774468 size: 252 magic: 2 compresscodec: NONE crc: 2796351311 isvalid: true
| offset: 1 CreateTime: 1599775774463 keysize: 1 valuesize: 9 sequence: -1 headerKeys: [] key: 5 payload: 33.440664
| offset: 2 CreateTime: 1599775774463 keysize: 8 valuesize: 9 sequence: -1 headerKeys: [] key: 60024247 payload: 9.1408728
| offset: 3 CreateTime: 1599775774463 keysize: 1 valuesize: 9 sequence: -1 headerKeys: [] key: 1 payload: 45.348946
| offset: 4 CreateTime: 1599775774464 keysize: 6 valuesize: 10 sequence: -1 headerKeys: [] key: 241795 payload: -63.786373
| offset: 5 CreateTime: 1599775774465 keysize: 8 valuesize: 9 sequence: -1 headerKeys: [] key: 53596698 payload: 69.431393
| offset: 6 CreateTime: 1599775774465 keysize: 8 valuesize: 9 sequence: -1 headerKeys: [] key: 33219463 payload: 88.307875
| offset: 7 CreateTime: 1599775774466 keysize: 1 valuesize: 9 sequence: -1 headerKeys: [] key: 0 payload: 39.940350
| offset: 8 CreateTime: 1599775774467 keysize: 5 valuesize: 9 sequence: -1 headerKeys: [] key: 78496 payload: 74.180098
| offset: 9 CreateTime: 1599775774468 keysize: 8 valuesize: 9 sequence: -1 headerKeys: [] key: 89866187 payload: 79.459314

dump-log 命令提供了大量信息。您可以清楚地看到每个记录的键、payload (值)、偏移量和时间戳

需要注意的是,上面输出的数据来自仅包含10条消息的演示主题,因此对于真实主题,将有更多的数据。

另外,在本例中,主题的键和值都是字符串。如果要使用非字符串的键或值类型,可以在运行 kafka-dump-log 命令的时候加上 --key-decoder-class 或 --value-decoder-class 标记即可。

相关文章