当前位置: 首页 > news >正文

kafka命令

查询kafka版本信息
kafka-configs.sh --describe --bootstrap-server  localhost:9092 --version


查看所有topic
[root@m10 bin]# kafka-topics.sh --list --zookeeper localhost:2181
__consumer_offsets
kahn-topic-1
my_topic
x_topic-1

创建一个topic,名为x_topic-1
[root@m10 bin]# kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic x_topic-1

查看名为x_topic-1的主题
[root@m10 bin]# kafka-topics.sh --describe --zookeeper localhost:2181 --topic x_topic-1
Topic:x_topic-1 PartitionCount:5        ReplicationFactor:1     Configs:
        Topic: x_topic-1        Partition: 0    Leader: 0       Replicas: 0     Isr: 0
        Topic: x_topic-1        Partition: 1    Leader: 0       Replicas: 0     Isr: 0
        Topic: x_topic-1        Partition: 2    Leader: 0       Replicas: 0     Isr: 0
        Topic: x_topic-1        Partition: 3    Leader: 0       Replicas: 0     Isr: 0
        Topic: x_topic-1        Partition: 4    Leader: 0       Replicas: 0     Isr: 0

将名为x_topic-1的主题的分区增加到5(分区编号从0开始,分区只能增加,不能减少)
[root@m10 bin]# kafka-topics.sh --zookeeper localhost:2181 --alter --topic x_topic-1 --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
Adding partitions succeeded!

查询指定topic(x_topic-1)的offset最小值
[root@m10 bin]# kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list 127.0.0.1:9092 -topic x_topic-1 --time -2
x_topic-1:0:0
x_topic-1:1:0
x_topic-1:2:0
x_topic-1:3:0
x_topic-1:4:0
查询指定topic(x_topic-1)的offset最大值
[root@m10 bin]# kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list 127.0.0.1:9092 -topic x_topic-1 --time -1
x_topic-1:0:10
x_topic-1:1:0
x_topic-1:2:0
x_topic-1:3:0
x_topic-1:4:0

删除名为my_topic的topic
[root@m10 bin]# kafka-topics.sh --zookeeper localhost:2181 --topic my_topic --delete 
Topic my_topic is marked for deletion.
Note: This will have no impact if delete.topic.enable is not set to true.


对名为x_topic-1的topic设置过期时间为24小时=86400000ms
[root@m10 bin]# kafka-configs.sh --zookeeper localhost:2181 --alter --entity-name x_topic-1 --entity-type topics --add-config retention.ms=86400000
Completed Updating config for entity: topic 'x_topic-1'.


查看名为x_topic-1的topic的过期时间
[root@m10 bin]# kafka-configs.sh --zookeeper localhost:2181 --describe --entity-name x_topic-1 --entity-type topics
Configs for topic 'x_topic-1' are retention.ms=86400000

生产消息:向名为x_topic-1的topic主题生产消息
[root@m10 bin]# kafka-console-producer.sh --broker-list localhost:9092 --topic x_topic-1
>heihei1
>heihei2
>
>[root@m10 bin]# 


消费消息:从名为x_topic-1的topic主题消费消息,--from-beginning从头开始
[root@m10 bin]# kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic x_topic-1 --from-beginning
quit
heihei1
"x_value-3690"                  #<-这几条消息只之前的,不知道为啥显示出来了
"x_value-3690-2"                #<-这几条消息只之前的,不知道为啥显示出来了
"x_value-3690-3"                #<-这几条消息只之前的,不知道为啥显示出来了
{"name": "serena", "age": 18}   #<-这几条消息只之前的,不知道为啥显示出来了
{"name": "serena", "age": 18}   #<-这几条消息只之前的,不知道为啥显示出来了
{"name": "serena", "age": 18}   #<-这几条消息只之前的,不知道为啥显示出来了
{"name": "serena", "age": 18}   #<-这几条消息只之前的,不知道为啥显示出来了
{"name": "serena", "age": 19}   #<-这几条消息只之前的,不知道为啥显示出来了
{"name": "serena", "age": 19}   #<-这几条消息只之前的,不知道为啥显示出来了
{"name": "serena", "age": 20}   #<-这几条消息只之前的,不知道为啥显示出来了
{"name": "serena", "age": 21}   #<-这几条消息只之前的,不知道为啥显示出来了
heihei2


消费消息:从名为x_topic-1的topic主题消费消息,从尾开始
[root@m10 bin]# kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic x_topic-1 --offset latest --partition 0
{"name": "serena", "age": 24}
{"name": "serena", "age": 25}


查看消费组列表
[root@m10 bin]# kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list
console-consumer-35505    #<---如果还没指定过消费组,系统貌似会自动生成一个

查看指定消费group(上面查到的console-consumer-35505)状态和消费详情
[root@m10 bin]# kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group console-consumer-35505 --describe
Consumer group 'console-consumer-35505' has no active members


自带压测工具
[root@m10 bin]# kafka-producer-perf-test.sh --topic x_topic-1 --num-records 100 --record-size 1 --throughput 100 --producer-props bootstrap.servers=localhost:9092
100 records sent, 99.800399 records/sec (0.00 MB/sec), 5.05 ms avg latency, 120.00 ms max latency, 2 ms 50th, 13 ms 95th, 120 ms 99th, 120 ms 99.9th.

http://www.lryc.cn/news/68424.html

相关文章:

  • mybatis多表查询
  • kafka 从入门到精通
  • 写PPT没有思路, 这些底层方法论让你灵感爆棚……
  • 【小沐学Python】Python实现Web服务器(Flask+Vue+node.js,web单页增删改查)
  • 甘肃非煤矿山电子封条 智慧矿山 opencv
  • 工业识别与定位系统源码解决方案
  • PCL学习之滤波算法
  • 第二章 链表
  • Spring Security OAuth2实现单点登录:简化多个系统之间的登录流程
  • 语义分析器
  • 爬虫基本原理
  • 常见电子元器件和电路
  • English Learning - L3 Lesson1 VOA-Color 译文
  • 如何在linux中配置JDK环境变量
  • 横截面收益率(二) 阿尔法策略是如何构建的
  • 【ConfluxNews】2023.5.15 警惕任何未经合约审计的项目
  • MySQL学习---17、MySQL8其它新特性
  • 快速入门matlab——变量练习
  • c++ 11标准模板(STL) std::set(三)
  • ChatGPT详细介绍
  • 【算法】【算法杂谈】让[0,x)区间上的出现概率变为x^k
  • 【2023华为OD笔试必会25题--C语言版】《21 对称美学》——字符串、递归
  • 为减少来自环境使用的无线传感器网络的传输次数而开发的方法(Matlab代码实现)
  • springboot+vue滴答拍摄影项目(源码+文档)
  • SQL基础培训13-索引和优化
  • 拥抱5G发展机遇,从边缘计算上车
  • “前端”工匠系列(二):合格的工匠,怎么做好价值落地 | 京东云技术团队
  • Oracle11g下载与安装
  • 考研复试-软件工程
  • 软件测试选择题