一 介紹
Kafka是一種高吞吐量的分布式發(fā)布訂閱消息系統(tǒng),它可以處理消費者規(guī)模的網(wǎng)站中的所有動作流數(shù)據(jù)漠烧,下載地址如下:https://www.apache.org/dyn/closer.cgi?path=/kafka/0.10.2.0/kafka_2.11-0.10.2.0.tgz
二 啟動
#啟動zookeeper
bin/zookeeper-server-start.sh config/zookeeper.properties
#更改配置
vi config/server.properties
#編輯內容如下
delete.topic.enable=true
listeners=PLAINTEXT://192.168.43.27:9092
#保存退出
#啟動kafka服務端
bin/kafka-server-start.sh config/server.properties
三 創(chuàng)建主題
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
# 列出主題列表
bin/kafka-topics.sh --list --zookeeper localhost:2181
# 刪除主題
bin/kafka-topics.sh --delete --zookeeper 192.168.43.27:2181 --topic road
四 創(chuàng)建消息
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
#發(fā)送消息
This is a message
This is another message
五 接收消息
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
this is a message
this is a another message
六 遇到的問題
在生產消息時腔剂,發(fā)生如下問題:
WARN Error while fetching metadata with correlation id 1 : {test=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
查看日志如下:
Registered broker 0 at path /brokers/ids/0 with addresses:
PLAINTEXT -> EndPoint(218.30.64.194,9092,PLAINTEXT) (kafka.utils.ZkUtils)
ip是218.30.64.194不是localhost媒区,沒有綁定Kafka啟動監(jiān)聽的host信息,只需更改配置文件綁定即可掸犬。
vi config/server.properties
#修改配置如下:
#原配置:listeners=PLAINTEXT://:9092
listeners=PLAINTEXT://localhost:9092
重修啟動zookeeper和kafka即可袜漩。