初步了解一下一下kafka的基本用法。
win7 64 bit
jdk1.7
1)下载kafka_2.10-0.8.2.1.tgz并解压(整合scala)
2)修改配置文件(可选)
config/zookeeper.properties
3)启动zookeeper(窗口1)
4)zookeeper测试
(窗口2)
5)启动kafka
(窗口3)
6)创建topic
(窗口4)
kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 3 --topic mytopic
7)查看topic
(窗口4)
kafka-topics.bat --describe --zookeeper localhost:2181 --topic
mytopic
8)发布/生产消息窗口
(窗口5)
kafka-console-producer.bat --broker-list localhost:9092 --topic
mytopic
有一个错误提示,但是不影响(kafa的bugKAFKA-1711,KAFKA-1824,预计0.9修复)
9)消费消息窗口
(窗口6)
kafka-console-consumer.bat --zookeeper localhost:2181 --from-beginning --topic
mytopic
10)producer窗口输入,可以在consumer窗口输出
11)znode查看
12)检查offset(窗口4)
注意:group为consumerid,需要在zk里面查ls /consumer
D:\fk\tech\kafka\kafka_2.10-0.8.2.1\kafka_2.10-0.8.2.1\bin\windows>kafka-consume
r-offset-checker.bat --topic mytopic --zookeeper localhost:2181 --broker-info 1
27.0.0.1:9092 --group console-consumer-64061
Group Topic Pid Offset logSize
Lag Owner
console-consumer-64061 mytopic 0 4 4
0 console-consumer-64061_zynb0411-1443580144073-95285fc3
-0
console-consumer-64061 mytopic 1 1 1
0 console-consumer-64061_zynb0411-1443580144073-95285fc3
-0
console-consumer-64061 mytopic 2 1 1
0 console-consumer-64061_zynb0411-1443580144073-95285fc3
-0
BROKER INFO
0 -> zynb0411:9092
D:\fk\tech\kafka\kafka_2.10-0.8.2.1\kafka_2.10-0.8.2.1\bin\windows>
13)simple-consumer(底层操作)
指定offset
D:\fk\tech\kafka\kafka_2.10-0.8.2.1\kafka_2.10-0.8.2.1\bin\windows>kafka-simple-
consumer-shell.bat --topic mytopic --offset 1 --broker-list 127.0.0.1:9092 --pa
rtition 0
error
this is a test msg from producer
中文
分别查看不同的partition
D:\fk\tech\kafka\kafka_2.10-0.8.2.1\kafka_2.10-0.8.2.1\bin\windows>kafka-simple-
consumer-shell.bat --topic mytopic --offset 0 --broker-list 127.0.0.1:9092 --pa
rtition 0
kafka
error
this is a test msg from producer
中文
终止批处理操作吗(Y/N)? y
D:\fk\tech\kafka\kafka_2.10-0.8.2.1\kafka_2.10-0.8.2.1\bin\windows>kafka-simple-
consumer-shell.bat --topic mytopic --offset 0 --broker-list 127.0.0.1:9092 --pa
rtition 1
go
终止批处理操作吗(Y/N)? y
D:\fk\tech\kafka\kafka_2.10-0.8.2.1\kafka_2.10-0.8.2.1\bin\windows>kafka-simple-
consumer-shell.bat --topic mytopic --offset 0 --broker-list 127.0.0.1:9092 --pa
rtition 2
hello
终止批处理操作吗(Y/N)? y
D:\fk\tech\kafka\kafka_2.10-0.8.2.1\kafka_2.10-0.8.2.1\bin\windows>