kafka命令工具创建查看topic信息

转载:https://www.jianshu.com/p/6cf6c7f208c9

 

1、创建topic

./bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic first --partitions 1 --replication-factor 1

./bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 3 --partitions 1 --topic first1

config cleanup.policy包含delete/compact

./bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 3 --partitions 12 --topic first2 --config delete.retention.ms=86400000 --config cleanup.policy=compact

2、查询topic,进入kafka目录:bin/kafka-topics.sh --list --zookeeper localhost:2181

3、查询topic./bin/kafka-topics.sh --list --bootstrap-server localhost:9092

4、查询topic内容:bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic first --from-beginning

5、查看topic 为 first的 详细信息./bin/kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic first

返回的信息如下

Topic:first PartitionCount:1 ReplicationFactor:1 Configs:segment.bytes=1073741824

Topic: first Partition: 0 Leader: 1 Replicas: 1 Isr: 1

6、往topic 为 first 的内部生产消息./bin/kafka-console-producer.sh --broker-list localhost:9092 --topic first

输入以下九条数据(包含空格)

 

nihao

nihao

你好

 

quit

exit

?

实时消费的

7、从topic 为first的内部消费消息,此时打开消费就能收到实时发送的消息了./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic first

8、查询当前topic某分区中数据的偏移量信息,注: time为-1时表示最大值,time为-2时表示最小值(可查看到包含9条数据信息)

./bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic first --time -1 --partitions 0

返回的信息

first:0:9

9、从指定的分区--partition 0,指定偏移量—offset 5,最大消息输出--max-messages 5(当接收够五条就会关闭接收请求,不设置次选项就会一直接受)查询当前topic信息

./bin/kafka-console-consumer.sh  --bootstrap-server localhost:9092 --topic first --partition 0 --offset 5 --max-messages 5 --property  print.timestamp=true

CreateTime:1684392637695 quit

CreateTime:1684392641949 exit

CreateTime:1684392913335 ?

CreateTime:1684392923551 实时消费的



作者:for笑
链接:https://www.jianshu.com/p/6cf6c7f208c9
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

posted on   叶子在行动  阅读(354)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示