kafka 安裝與配置

下載

地址:https://kafka.apache.org/downloadsapache

這裏下載的是kafka_2.11-0.11.0.1.tgzbootstrap

解壓ui

tar -xzf kafka_2.11-0.11.0.1.tgz
cd kafka_2.11-0.11.0.1server

啓動zookeeperget

$ bin/zookeeper-server-start.sh config/zookeeper.propertieskafka

默認使用的2181端口,可在配置文件修改。it

啓動kafka serverio

bin/kafka-server-start.sh config/server.propertiesconsole

(非本地生產者和消費者訪問Kafka,記得修改 config/server.properties中的listeners, 例如
listeners=PLAINTEXT://192.168.33.152:9092)class

create a topic

bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

查看topic

bin/kafka-topics.sh --list --zookeeper localhost:2181

好像沒有輸出

啓動生產者

$ bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test

輸入

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 another message

若是沒法啓動,根據提示,可能須要加zookeeper:

$ bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --zookeeper localhost:2181 --topic test --from-beginning

參考

kafka官網
https://kafka.apache.org/
https://kafka.apache.org/quickstart

相關文章
相關標籤/搜索