一、topic 相关命令
1.1 创建topic
创建topic ,包含3个partitions,每个partitions 有3个副本
bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic test --partitions 3 --replication-factor 3
创建topic ,手动分配副本
bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic test2 --replica-assignment 0:1,1:2,0:2
创建topic ,同时指定配置参数,max.message.bytes=10485760,flush.messages=100
bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic test --config max.message.bytes=10485760 --config flush.messages=100
1.2 topic列表
bin/kafka-topics.sh --bootstrap-server localhost:9092 --list
1.3 topic详情
bin/kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic test
1.4 修改topic
bin/kafka-topics.sh --bootstrap-server localhost:9092 --alter --topic test --partitions 3
1.5 删除topic
bin/kafka-topics.sh --bootstrap-server localhost:9092 --delete --topic test
二、producer相关命令
启动生产者,常规启动
bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic test
启动生产者,发送消失时带key,以”:”为key、value的分隔符
bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic test --property parse.key=true --property key.separator=:
三、consumer相关命令
从末尾开始拉取消息
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test
从头开始拉取消息
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
从指定offset开始拉取消息
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --partition 0 --offset 10
最多拉取10条
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --max-messages 10
打印key
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --property print.key=true
指定消费组
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning --group g1
四、groups相关命令
4.1 消费组列表
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list
4.2 消费组详情
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group g1
4.3 删除消费组
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --delete --group g1
五、config相关命令
6.1 查看配置
bin/kafka-configs.sh --bootstrap-server localhost:9092 --entity-type topics --entity-name test --describe
6.2 增加配置
bin/kafka-configs.sh --bootstrap-server localhost:9092 --entity-type topics --entity-name test --alter --add-config max.message.bytes=10485760,flush.messages=100
6.3 删除配置
bin/kafka-configs.sh --bootstrap-server localhost:9092 --entity-type topics --entity-name test --alter --delete-config max.message.bytes,flush.messages
六、吞吐量测试相关命令
6.1 生产者吞吐量测试
bin/kafka-producer-perf-test.sh bootstrap.servers=localhost:9092 --topic test --num-records 1000000 --record-size 200 --throughput -1 --producer-props acks=-1
6.2 消费者吞吐量测试
bin/kafka-consumer-perf-test.sh --bootstrap-server localhost:9092 --topic test --messages 1000000