Kafka 安裝搭建 應用

kafka下載: http://kafka.apache.org/downloads

tar -zxvf kafka_2.11-1.1.0.tgz  -C /usr/local/

啓動zookeeper

cat zookeeper.properties | grep -v '#' >> zk.properties
./bin/zookeeper-server-start.sh config/zk.properties

啓動kafka

cat config/server.properties | grep -v '#' >> config/kafka1.properties
./bin/kafka-server-start.sh config/kafka1.properties

創建主題

[root@iZ2ze3wauzpc3cefc0xha7Z]/usr/local/kafka_2.11-1.1.0# ./bin/kafka-topics.sh --create --zookeeper 0.0.0.0:2181 --replication-factor 1 --partitions 1 --topic test-topic
Created topic "test-topic".

生產

[root@iZ2ze3wauzpc3cefc0xha7Z]/usr/local/kafka_2.11-1.1.0# ./bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test-topic
>test
>ha
>mi
>dd

消費

[root@iZ2ze3wauzpc3cefc0xha7Z]/usr/local/kafka_2.11-1.1.0# ./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test-topic
hh

消費歷史

[root@iZ2ze3wauzpc3cefc0xha7Z]/usr/local/kafka_2.11-1.1.0# ./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test-topic --from-beginning
test
ha
mi
dd

zookeeper只能啓動單數,比如1臺 、3臺、7臺等等,不能偶數臺

kafka 與 spring 集成參考 demo https://github.com/menxu/mxmvcdemo

錯誤排查

這裏寫圖片描述

參考 https://www.tuicool.com/articles/3yQJFbr

需要配置 advertised.listeners=PLAINTEXT://xx.xx.xx.xx:9092

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章