topic 工具

https://cwiki.apache.org/confluence/display/KAFKA/Replication+tools

offset相关


# 最大offset
bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic test_topic --time -1 # 最小offset
bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic test_topic --time -2 # offset
bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic test_topic

topic相关

# 列出当前kafka所有的topic
bin/kafka-topics.sh --zookeeper localhost:2181 --list # 创建topic
bin/kafka-topics.sh --create --zookeeper localhost:2181 --topic test_topic --replication-factor 1 --partitions 1 bin/kafka-topics.sh --create --zookeeper localhost:2181 --topic test_topic --replication-factor 3 --partitions 10 --config cleanup.policy=compact bin/kafka-topics.sh --create --zookeeper localhost:2181 --topic test_topic --partitions 1   --replication-factor 1 --config max.message.bytes=64000 --config flush.messages=1 # 查看某topic具体情况
bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic test_topic # 修改topic(分区数、特殊配置如compact属性、数据保留时间等)
bin/kafka-topics.sh --zookeeper localhost:2181 --alter --partitions 3 --config cleanup.policy=compact --topic test_topic # 修改topic(也可以用这种)
bin/kafka-configs.sh --alter --zookeeper localhost:2181 --entity-name test_topic --entity-type topics --add-config cleanup.policy=compact bin/kafka-configs.sh --alter --zookeeper localhost:2181 --entity-name test_topic --entity-type topics --delete-config cleanup.policy

consumer-group相关


# 查看某消费组(consumer_group)具体消费情况(活跃的消费者以及lag情况等等)
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group test_group --describe # 列出当前所有的消费组
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list # 旧版
bin/kafka-consumer-groups.sh --zookeeper 127.0.0.1:2181 --group test_group --describe

consumer相关

# 消费数据(从latest消费)
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test_topic # 消费数据(从头开始消费)
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test_topic --from-beginning # 消费数据(最多消费多少条就自动退出消费)
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test_topic --max-messages 1 # 消费数据(同时把key打印出来)
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test_topic --property print.key=true # 旧版
bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test_topic

producer相关

# 生产数据
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test_topic # 生产数据(写入带有key的message)
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test_topic --property "parse.key=true" --property "key.separator=:"

producer-golang

# golang实现的kafka客户端
https://github.com/Shopify/sarama/tree/master/tools # Minimum invocation
kafka-console-producer -topic=test -value=value -brokers=kafka1:9092 # It will pick up a KAFKA_PEERS environment variable
export KAFKA_PEERS=kafka1:9092,kafka2:9092,kafka3:9092
kafka-console-producer -topic=test -value=value # It will read the value from stdin by using pipes
echo "hello world" | kafka-console-producer -topic=test # Specify a key:
echo "hello world" | kafka-console-producer -topic=test -key=key # Partitioning: by default, kafka-console-producer will partition as follows:
# - manual partitioning if a -partition is provided
# - hash partitioning by key if a -key is provided
# - random partioning otherwise.
#
# You can override this using the -partitioner argument:
echo "hello world" | kafka-console-producer -topic=test -key=key -partitioner=random # Display all command line options
kafka-console-producer -help

Kafka常用topic操作命令汇总的更多相关文章

  1. kafka常用的操作命令

    1.kafka启动命令 nohup bin/kafka-server-start.sh config/server.properties & 2.创建topic bin/kafka-topic ...

  2. kafka常用命令

    以下是kafka常用命令行总结: 0.查看有哪些主题: ./kafka-topics.sh --list --zookeeper 192.168.0.201:12181 1.查看topic的详细信息 ...

  3. Kafka各个版本差异汇总

    Kafka各个版本差异汇总   从0.8.x,0.9.x,0.10.0.x,0.10.1.x,0.10.2.x,0.11.0.x,1.0.x或1.1.x升级到2.0.0 Kafka 2.0.0引入了线 ...

  4. Kafka学习之四 Kafka常用命令

    Kafka常用命令 以下是kafka常用命令行总结: 1.查看topic的详细信息 ./kafka-topics.sh -zookeeper 127.0.0.1:2181 -describe -top ...

  5. kafka2:常用topic命令

    常用操作 创建一个topic bin/kafka-topics.sh --create --zookeeper 192.168.3.230:2181 --replication-factor 3 -- ...

  6. kafka常用的shell命令

    kafka常用shell命令: ------------------------------------ 1.创建topic bin/kafka-topics.sh --create --zookee ...

  7. 常用 Gulp 插件汇总 —— 基于 Gulp 的前端集成解决方案(三)

    前两篇文章讨论了 Gulp 的安装部署及基本概念,借助于 Gulp 强大的 插件生态 可以完成很多常见的和不常见的任务.本文主要汇总常用的 Gulp 插件及其基本使用,需要读者对 Gulp 有一个基本 ...

  8. 记录 git 常用的操作命令总结

    记录 git 常用的操作命令总结 2016-12-15 16:44:04 作为一名开发者,熟悉使用 git 代码管理工具是一项必备的基本技能.git 相较 SVN 而言,其优点不言而喻.git 的功能 ...

  9. 【帖子】怎么彻底删除kafka的topic,然后重建?

    怎么彻底删除kafka的topic,然后重建? 网上都说用kafka-run-class.shkafka.admin.DeleteTopicCommand 命令删除topic,但是并没有成功,用kaf ...

随机推荐

  1. 1078 字符串压缩与解压 (20分)C语言

    文本压缩有很多种方法,这里我们只考虑最简单的一种:把由相同字符组成的一个连续的片段用这个字符和片段中含有这个字符的个数来表示.例如 ccccc 就用 5c 来表示.如果字符没有重复,就原样输出.例如 ...

  2. 1052 卖个萌 (20 分)C语言

    萌萌哒表情符号通常由"手"."眼"."口"三个主要部分组成.简单起见,我们假设一个表情符号是按下列格式输出的: [左手]([左眼][口][右 ...

  3. gulp的简介以及使用方法

    环境介绍: pro环境:生产环境,面向外部用户的环境,连接上互联网即可访问的正式环境. pre环境:灰度环境,外部用户可以访问,但是服务器配置相对低,其它和生产一样. test环境:测试环境,外部用户 ...

  4. [技术翻译]使用Nuxt生成静态网站

    本周再来翻译一些技术文章,本次预计翻译三篇文章如下: 04.[译]使用Nuxt生成静态网站(Generate Static Websites with Nuxt) 05.[译]Web网页内容是如何影响 ...

  5. 配置ca服务器和http,mail加密

    一·CA介绍 certificate authority   数字证书授权中心 被通信双方信任的.独立的第三方机构 负责证书颁发.验证.撤销等管理 数字证书 经证书授权中心数字签名的包含公开密钥拥有者 ...

  6. [MariaDB]MHA高可用部署-实验

    目录 一.简介 1.1MHA角色 二.MHA的工具 三.MHA部署过程 3.1.1 配置 3.1.2 环境规划 3.1.3 配置一主多从 3.2 MHA配置 3.2.1 master权限授予 3.2. ...

  7. VScode(一):C/C++ & MinGW & Code Runner

    目录 1 VScode配置安装 2 MinGW配置安装 2.1 MinGW下载安装 2.2 MinGW环境配置 3 VScode编译C/C++ 3.1 扩展插件安装 3.2 项目配置 3.2.1 配置 ...

  8. cogs 2109. [NOIP 2015] 运输计划 提高组Day2T3 树链剖分求LCA 二分答案 差分

    2109. [NOIP 2015] 运输计划 ★★★☆   输入文件:transport.in   输出文件:transport.out   简单对比时间限制:3 s   内存限制:256 MB [题 ...

  9. 替代not in 和 in 的办法

    在程序中,我们经常会习惯性的使用in和not in,在访问量比较小的时候是可以的,但是一旦数据量大了,我们就推荐使用not exists或者外连接来代替了.如果要实现一张表有而另外一张表没有的数据时, ...

  10. python 打印乘法表

    for i in range(1, 10): for j in range(1, i+1): print('%s * %s = %s' % (i, j, i*j), end=' ') print('' ...