1.安裝kafka
brew install kafka
note:
·kafka使用zookeeper管理,安裝過程會自動安裝zookeeper
·安裝目錄:/usr/local/Cellar/kafka/* (*為具體安裝的版本)
·配置文件目錄:/usr/local/etc/kafka
2.修改kafka啟動配置文件
vi /usr/local/etc/kafka/server.properties
note:
·該配置為單機版,集群配置另開文章講述
修改kafka的監聽地址和端口為localhost:9092
listeners=PLAINTEXT://localhost:9092
3.依次啟動服務
brew services start zookeeper
brew services start kafka
note:
·由於kafka依賴zookeeper管理,所以zookeeper需要先啟動
4.創建topic
使用單個分區和只有一個副本的方式來創建一個名為“test”的topic
kafka-topics --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
5.查看創建的topic
kafka-topics --list --zookeeper localhost:2181
6.生產消息
通過控制台向“test”topic添加消息
kafka-console-producer --broker-list localhost:9092 --topic test
7.消費消息
通過控制台消費“test”topic中的消息
kafka-console-consumer --bootstrap-server localhost:9092 --topic test --from-beginning
