目录

简介

操作

创建 --create

列表 --list

详细信息 --describe

删除 --delete

修改 --alter

基本参数


简介

kafka-topics.bat 脚本负责主题(topic)相关操作。通过kafka-run-class 调用kafka.admin.TopicCommand类。

操作

创建 --create

--create 创建

--zookeeper zookeeper地址

--replication-factor 副本数

--partitions 分区数量

因为该环境非集群环境,所以这里副本数设置为1。

D:\DEV\MQ\kafka_2.12-2.3.0\kafka_2.12-2.3.0\bin\windows>kafka-topics.bat --create --zookeeper localhost:2181 --topic Hello-Kafka --partitions 5 --replication-factor 1
Created topic Hello-Kafka.

创建完成后,可看到logs目录下生成了5个新的目录,命名规则为TopicsName-分区ID。

列表 --list

--list 查看

D:\DEV\MQ\kafka_2.12-2.3.0\kafka_2.12-2.3.0\bin\windows>kafka-topics.bat --list --zookeeper localhost:2181
Hello-Kafka
__consumer_offsets

详细信息 --describe

--describe 查看

--topic 指定查看哪个主题,如果不写该参数则会显示全部主题。

D:\DEV\MQ\kafka_2.12-2.3.0\kafka_2.12-2.3.0\bin\windows>kafka-topics.bat --zookeeper localhost:2181 --describe --topic Hello-Kafka
Topic:Hello-Kafka       PartitionCount:5        ReplicationFactor:1     Configs:Topic: Hello-Kafka      Partition: 0    Leader: 0       Replicas: 0     Isr: 0Topic: Hello-Kafka      Partition: 1    Leader: 0       Replicas: 0     Isr: 0Topic: Hello-Kafka      Partition: 2    Leader: 0       Replicas: 0     Isr: 0Topic: Hello-Kafka      Partition: 3    Leader: 0       Replicas: 0     Isr: 0Topic: Hello-Kafka      Partition: 4    Leader: 0       Replicas: 0     Isr: 0

PartitionCount:分区个数。
ReplicationFactor:副本个数。
Partition:分区编号,从 0 开始递增。
Leader:当前 分区起作用的 breaker.id。
Replicas: 当前副本数据所在的 breaker.id,是一个列表,排在最前面的其作用。
Isr:当前 kakfa 集群中可用的 breaker.id 列表。

删除 --delete

--delete 删除

D:\DEV\MQ\kafka_2.12-2.3.0\kafka_2.12-2.3.0\bin\windows>kafka-topics.bat --delete --topic Hello-Kafka --zookeeper localhost:2181
Topic Hello-Kafka is marked for deletion.
Note: This will have no impact if delete.topic.enable is not set to true.

如果 delete.topic.enable = true

则会立刻删除掉该主题,否则只会标记为删除,并不会真正删除。需要到zk中删除该topic。

修改 --alter

新增分区

分区从5改为6

D:\DEV\MQ\kafka_2.12-2.3.0\kafka_2.12-2.3.0\bin\windows>kafka-topics.bat --alter --zookeeper localhost:2181 --topic Hello-Kafka --partitions 6
WARNING: If partitions are increased for a topic that has a key, the partition logic or ordering of the messages will be affected
Adding partitions succeeded!

减少分区 - 不可能

D:\DEV\MQ\kafka_2.12-2.3.0\kafka_2.12-2.3.0\bin\windows>kafka-topics.bat --alter --zookeeper localhost:2181 --topic Hello-Kafka --partitions 5
WARNING: If partitions are increased for a topic that has a key, the partition logic or ordering of the messages will be affected
Error while executing topic command : The number of partitions for a topic can only be increased. Topic Hello-Kafka currently has 6 partitions, 5 would not be an increase.
[2021-06-03 23:19:28,955] ERROR org.apache.kafka.common.errors.InvalidPartitionsException: The number of partitions for a topic can only be increased. Topic Hello-Kafka currently has 6 partitions, 5 would not be an increase.(kafka.admin.TopicCommand$)

基本参数

D:\DEV\MQ\kafka_2.12-2.3.0\kafka_2.12-2.3.0\bin\windows>kafka-topics.bat
Create, delete, describe, or change a topic.
Option                                   Description
------                                   -----------
--alter                                  Alter the number of partitions,replica assignment, and/orconfiguration for the topic.
--at-min-isr-partitions                  if set when describing topics, onlyshow partitions whose isr count isequal to the configured minimum. Notsupported with the --zookeeperoption.
--bootstrap-server <String: server to    REQUIRED: The Kafka server to connectconnect to>                              to. In case of providing this, adirect Zookeeper connection won't berequired.
--command-config <String: command        Property file containing configs to beconfig property file>                    passed to Admin Client. This is usedonly with --bootstrap-server optionfor describing and altering brokerconfigs.
--config <String: name=value>            A topic configuration override for thetopic being created or altered.Thefollowing is a list of validconfigurations:cleanup.policycompression.typedelete.retention.msfile.delete.delay.msflush.messagesflush.msfollower.replication.throttled.replicasindex.interval.bytesleader.replication.throttled.replicasmax.message.bytesmessage.downconversion.enablemessage.format.versionmessage.timestamp.difference.max.msmessage.timestamp.typemin.cleanable.dirty.ratiomin.compaction.lag.msmin.insync.replicaspreallocateretention.bytesretention.mssegment.bytessegment.index.bytessegment.jitter.mssegment.msunclean.leader.election.enableSee the Kafka documentation for fulldetails on the topic configs.It issupported only in combination with --create if --bootstrap-server optionis used.
--create                                 Create a new topic.
--delete                                 Delete a topic
--delete-config <String: name>           A topic configuration override to beremoved for an existing topic (seethe list of configurations under the--config option). Not supported withthe --bootstrap-server option.
--describe                               List details for the given topics.
--disable-rack-aware                     Disable rack aware replica assignment
--exclude-internal                       exclude internal topics when runninglist or describe command. Theinternal topics will be listed bydefault
--force                                  Suppress console prompts
--help                                   Print usage information.
--if-exists                              if set when altering or deleting ordescribing topics, the action willonly execute if the topic exists.Not supported with the --bootstrap-server option.
--if-not-exists                          if set when creating topics, theaction will only execute if thetopic does not already exist. Notsupported with the --bootstrap-server option.
--list                                   List all available topics.
--partitions <Integer: # of partitions>  The number of partitions for the topicbeing created or altered (WARNING:If partitions are increased for atopic that has a key, the partitionlogic or ordering of the messageswill be affected
--replica-assignment <String:            A list of manual partition-to-brokerbroker_id_for_part1_replica1 :           assignments for the topic beingbroker_id_for_part1_replica2 ,           created or altered.broker_id_for_part2_replica1 :broker_id_for_part2_replica2 , ...>
--replication-factor <Integer:           The replication factor for eachreplication factor>                      partition in the topic being created.
--topic <String: topic>                  The topic to create, alter, describeor delete. It also accepts a regularexpression, except for --createoption. Put topic name in doublequotes and use the '\' prefix toescape regular expression symbols; e.g. "test\.topic".
--topics-with-overrides                  if set when describing topics, onlyshow topics that have overriddenconfigs
--unavailable-partitions                 if set when describing topics, onlyshow partitions whose leader is notavailable
--under-min-isr-partitions               if set when describing topics, onlyshow partitions whose isr count isless than the configured minimum.Not supported with the --zookeeperoption.
--under-replicated-partitions            if set when describing topics, onlyshow under replicated partitions
--version                                Display Kafka version.
--zookeeper <String: hosts>              DEPRECATED, The connection string forthe zookeeper connection in the formhost:port. Multiple hosts can begiven to allow fail-over.

Kafka操作之kafka-topics相关推荐

  1. 如何为一个kafka集群选择topics/partitions的数量

    2019独角兽企业重金招聘Python工程师标准>>> How to choose the number oftopics/partitions in a Kafka cluster ...

  2. ELK集群部署(六)之Kafka操作

    Kafka操作 1.创建topic /usr/local/src/kafka_2.12-3.2.0/bin/kafka-topics.sh --create --bootstrap-server 19 ...

  3. kafka学习--使用kafka conect操作kafka connector

    1. 配置kafka connectors kafka connectors配置是简单的键值映射.对于独立模式,这些在属性文件中定义,并传递到命令行上的kafka Connect进程.在分布式模式下, ...

  4. CC00073.kafka——|Hadoopkafka.V58|——|kafka.v58|稳定性|事务操作|

    一.事务操作 ### --- 事务操作~~~ # 在Kafka事务中,一个原子性操作,根据操作类型可以分为3种情况.情况如下: ~~~ 只有Producer生产消息,这种场景需要事务的介入: ~~~ ...

  5. 基于jmx监控kafka_0542-6.1.0-非安全环境下Kafka管理工具Kafka Eagle安装使用

    1.文档编写目的 Fayson在前面的文章介绍了<0374-如何在CDH集群中部署Kafka Manager>,本篇文章Fayson介绍另外一款的监控工具Kafka-eagle,它可以同时 ...

  6. kafka专题:kafka单机和集群安装详情,Spring Boot如何整合Kafka

    文章目录 1. kafka单机安装 1.1 server.properties核心配置 2. kafka集群安装 2.1 kafka集群可视化界面 3. springboot如何整合kafka 4. ...

  7. OpenShift 4 之Kafka(2)-配置Kafka Bridge,通过HTTP访问Kafka Topic

    <OpenShift 4.x HOL教程汇总> 文章目录 Kafka Bridge的功能 配置Kafka Bridge 测试验证Kafka Bridge 发消息 收消息 Kafka Bri ...

  8. Kafka(三)、Kafka架构

    Kafka架构 一.Kafka 基本介绍 1.1 什么是Kafka 1.2 Kafka特性 1.3 常见应用场景 二.Kafka 系统架构 2.1 基本概念 2.2 index / timeindex ...

  9. Kafka教程(一)Kafka入门教程

    Kafka教程(一)Kafka入门教程 1 Kafka入门教程 1.1 消息队列(Message Queue) Message Queue消息传送系统提供传送服务.消息传送依赖于大量支持组件,这些组件 ...

  10. 最新Kafka教程(包含kafka部署与基本操作、java连接kafka、spring连接kafka以及使用springboot)

    最新Kafka教程(包含kafka部署与基本操作.java连接kafka.spring连接kafka以及使用springboot) 欢迎转载,转载请注明网址:https://blog.csdn.net ...

最新文章

  1. 沙龙预告 | 新书分享《崛起的超级智能:互联网大脑如何影响科技未来》
  2. 【MVC】Controller的使用
  3. docker安装influxdb、grafana及展示数据到grafana
  4. 前端学习(1975)vue之电商管理系统电商系统之渲染参数下的可选项
  5. C/C++ 去掉字符串首位的空格字符
  6. 自定义工作流界面开发
  7. 关于预编绎网站的问题[已预编译此应用程序的错误]
  8. 为什么复制粘贴格式总是出错_想把图片转换成pdf格式怎么做?你找对方法了吗...
  9. 一个简单的解决方法:word文档打不开,错误提示mso.dll模块错误。
  10. iphone双重认证关闭不了怎么办_怎么关闭iPhone手机双重认证? 关闭苹果手机双重认证的两种操作方法...
  11. Win7系统怎么开启远程桌面?Win7远程桌面怎么用
  12. 微服务之服务网关Gateway
  13. numpy 数组的旋转、上下翻转、镜像
  14. oracle部门总工资的函数,Oracle分析函数
  15. 即食水产消费品公司“不等食品”获千万元级A轮融资,险峰长青领投
  16. 【性能定位】使用jstack定位线程堆栈信息
  17. 怎样将图片体积缩小?如何一键完成图片压缩?
  18. 轻松bypass360网站卫士WAFSQL注入防护
  19. POI导出excel并设置单元格样式和单元格内容中文自适应
  20. Xmos startkit 开篇-硬件介绍

热门文章

  1. 在chrome中屏蔽百度推荐
  2. docker部署内网dns解析服务(coredns方案)
  3. element UI的带输入建议el-autocomplete总结(详细,全)
  4. Hyper-V安装Server 2019虚拟机
  5. CMDN Club #23 开放平台和O2O移动产品开发
  6. 在c语言中卖水果的程序,C语言写的简易水果管理系统
  7. 有限域(Galois Field,GF,伽罗华域)的乘法原理
  8. excel将大表分解成小表,将小表合成一个大表
  9. 上线项目 Docker部署项目到服务器总结
  10. 利用谷歌镜像网站编辑Latex的参考文献与doi链接