Kafka Topic Create & Detail

创建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文件,供后续直接使用
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值