Kafka 簡介
是一個分佈式消息隊列,高吞吐量,使用Scala實現。
安裝
1.安裝JDK
2.下載zookeeper和kafka,解壓到某個目錄下面,比如我的是 D:\dev
3.修改zookeeper的配置文件,位於D:\dev\zookeeper-3.4.8\conf
,把zoo_sample.cfg重命名爲zoo.cfg,修改裏面的存儲目錄dataDir和端口號。
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just example sakes.
dataDir=D:\dev\zookeeper-3.4.8\data
# the port at which the clients will connect
clientPort=2181
4.啓動zookeeper(運行bin下面的zkServer,或者修改環境變量path)。
5.修改kafka配置(server.properties),主要看到裏面配置了zookeeper的地址信息,這裏在本機。
6.啓動kafka server,啓動腳本是D:\dev\kafka_2.11-0.10.0.1\bin\kafka-server-start.sh,後面的類似。
D:\dev\kafka_2.11-0.10.0.1>.\bin\windows\kafka-server-start.bat .\config\server.
properties
7.創建一個topic,如”test2”。
D:\dev\kafka_2.11-0.10.0.1>.\bin\windows\kafka-topics.bat --create --zookeeper l
ocalhost:2181 --replication-factor 1 --partitions 1 --topic test2
8.打開消息生成者和消費者,然後可以看到生產者發送的消息會到達消費者。
D:\dev\kafka_2.11-0.10.0.1>.\bin\windows\kafka-console-producer.bat --broker-lis
t localhost:9092 --topic test2
D:\dev\kafka_2.11-0.10.0.1>.\bin\windows\kafka-console-consumer.bat --zookeeper
localhost:2181 --topic test2
小結
慢慢摸索。