Kafka
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