Kafka命令

Kafka

官网: https://kafka.apache.org/


kafka 2.8.0版本提出放弃zookeeper,到3.0版本,这个愿望大致实现

– 使用zookeeper时,访问命令加 --zookeeper localhost:2181

– 不使用zookeeper时,访问命令加 -bootstrap-server localhost:9092

1. Topic相关

1.1列出所有topic

./kafka-topic.sh --list --bootstrap-server localhost:9092

1.2创建topic

# --partitions 分区数   --replication-factor副本数 
bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --partitions 3 --replication-factor 2 --topic testTopic

1.3查看topic详情

bin/kafka-topics.sh --describe --bootstrap-server localhost:9092  --topic testTopic

1.4 删除topic

bin/kafka-topics.sh --delete --bootstrap-server localhost:9092  --topic testTopic

2. offset 相关

# 查询现有offset的堆积数据
./kafka-consumer-groups.sh --bootstrap-server localhost:9092 -describe -group groupName

# 根据时间查询偏移量
./kafka-run-class.sh kafka.tools.GetOffsetShell --bootstrap-server localhost:9092 --topic topic-name  --time  "$(date -d "2024-08-29 17:00:00" +%s)000" 

# 调整offset到指定日期
./kafka-consumer-groups.sh --bootstrap-server localhost:9092 --topic testTopic  --group groupName --reset-offsets --to-datetime 2024-07-24T06:50:00.000 --execute

3 消息读取

# 持续读最新
sh kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topic-name 

# 指定位置10条
sh kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topic-name --partition 0 --offset 362237879 --max-messages 10 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值