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
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)