创建Topic
topic: test 副本:1个 分区:3个
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 3 --topic test
查看topic列表
bin/kafka-topics.sh --list --zookeeper localhost:2181
查看topic详情
bin/kafka-topics.sh --zookeeper localhost:2181 --topic test --describe
生产者
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
消费者
注意:
① --from-beginning 可以从头开始消费
② --group test 指定消费者组
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --group test --from-beginning
消费者组列表
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list
消费者组详情
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group test --describe
删除topic
注意:需要在server.properties配置文件里加 delete.topic.enable=true参数
bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic test
修改分区
注:只能增加 不能减少
bin/kafka-topics.sh --zookeeper localhost:2181 --alter --topic test --partitions 3
修改offset
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group test --topic test --execute --reset-offsets --to-offset 10000
参数详解:
Topic的作用域:
- - - all-topics:为consumer group下所有topic的所有分区调整位移
- - - topic test1 - - topic test2 :为指定的若干个topic的所有分区调整位移
- - - topic test1:0,1,2 :为指定的topic分区调整位移
重置策略
- - - to-earliest:把位移调整到分区当前最小位移
- - - to-latest:把位移调整到分区当前最新位移
- - - to-current:把位移调整到分区当前位移
- - - to-offset : 把位移调整到指定位移处
- - - shift-by N: 把位移调整到当前位移 + N处,注意N可以是负数,表示向前移动
- - - to-datetime :把位移调整到大于给定时间的最早位移处,datetime格式是yyyy-MM-ddTHH:mm:ss.xxx,比如2017-08-04T00:00:00.000
- - - by-duration :把位移调整到距离当前时间指定间隔的位移处,duration格式是PnDTnHnMnS,比如PT0H5M0S
- - - from-file :从CSV文件中读取调整策略
确定执行方案
注:什么参数都不加:只是打印出位移调整方案,不具体执行
- - - execute:执行真正的位移调整
- - - export:把位移调整方案按照CSV格式打印,方便用户成csv文件,供后续直接使用