Mac可以使用brew自动安装所需软件,先要确认已经安装好了java。
安装
brew install kafka
brew install zookeeper
#查看软件是否已经安装
brew list
修改 /usr/local/etc/kafka/server.properties, 找到 listeners=PLAINTEXT://:9092 那一行,把注释取消掉。
然后修改为:
listeners=PLAINTEXT://localhost:9092
启动
如果想以服务的方式启动,那么可以:
brew services start zookeeper
brew services start kafka
如果只是临时启动,可以:
zkServer start
kafka-server-start /usr/local/etc/kafka/server.properties
创建Topic
kafka-topics --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
产生消息
kafka-console-producer --broker-list localhost:9092 --topic test
> HELL World
消费
简单方式
kafka-console-consumer --bootstrap-server localhost:9092 --topic test --from-beginning
kafka-console-consumer --bootstrap-server localhost:9092 --topic test --group test-consumer1 --from-beginning