kafka use

kafka 常用命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//查看topic
bin/kafka-topics.sh --zookeeper localhost:2181 --list

//创建3个副本的topic
bin/kafka-topics.sh --zookeeper localhost:2181 --create --replication-factor 3 --partitions 1 --topic my-replicated-topic

//查看topic状态
bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic my-replicated-topic

//删除topic
bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic my-replicated-topic

//发送数据
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic my-replicated-topic

//消费数据
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic my-replicated-topic --from-beginning
1
2
3
4
5
6
7
//查看当前消费者是否已经读到最新的数据
[wisdom@10 ~]$ /mnt/app/kafka/bin/kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --group Booking --zookeeper 10.0.3.65:2181 --topic Booking
[2017-03-17 14:35:48,094] WARN WARNING: ConsumerOffsetChecker is deprecated and will be dropped in releases following 0.9.0. Use ConsumerGroupCommand instead. (kafka.tools.ConsumerOffsetChecker$)
Group Topic Pid Offset logSize Lag Owner
Booking Booking 0 101 166 65 Booking_470_636253289830976972-0
Booking Booking 1 97 167 70
Booking_470_636253289830976972-0