Kafka是一种开源分布式事件流平台,可以应用在相当多的方面。
本文介绍一种快速部署与使用的方法。
1.首先到
http://kafka.apache.org/downloads
下载kafka。解压缩。
解压以后目录如下:
可以看到,有一个bin下面有一个windows目录,这里提供可以在windows中运行的bat文件
2. 然后到kafak/config目录下,设置zookeeper端口。
编辑 zookeeper.properties
# the port at which the clients will connect
clientPort=2181
以及 server.properties
# Zookeeper connection string (see zookeeper docs for details).
# This is a comma separated host:port pairs, each corresponding to a zk
# server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002".
# You can also append an optional chroot string to the urls to specify the
# root directory for all kafka znodes.
zookeeper.connect=localhost:2181
3. 如果在windows下,请将kafka/bin/windows加入到环境变量path中,以便直接通过命令文件启动
4. 启动
打开命令行,到kafka/config目录下,
运行命令启动zookeeper
zookeeper-server-start zookeeper.properties
运行命令启动kafka
kafka-server-start server.properties
启动完毕。
5. 创建topic ,名字为test
kafka-topics --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
6.向test中生产message
kafka-console-producer.sh --broker-list localhost:9092 --topic test
7.消费message
kafka-console-consumer --bootstrap-server localhost:9092 --topic test --from-beginning
转自 烂代码
https://www.trashcode.cn/post/d/ae3ffb58-0104-497b-8019-223baa916f3f