作者:crane-yuan 日期:2017-08-31
介绍
Apache Kafka was originated at LinkedIn and later became an open sourced Apache project in 2011, then First-class Apache project in 2012. Kafka is written in Scala and Java. Apache Kafka is publish-subscribe based fault tolerant messaging system. It is fast, scalable and distributed by design.
安装kafka服务器
kafka启动需要依赖zookeeper和Java8环境,所以需要先安装zookeeper和java8
注:本人实验使用的kafka版本为0.8.2.x
ArchLinux下安装命令
> yaourt -S zookeeper
> yaourt -S java8
> yaourt -S kafka #可以自己修改PKGBUILD文件,安装指定版本
Mac下安装命令
> brew install zookeeper
> brew cask install java
> brew install kafka
配置zookeeper
tickTime=2000
dataDir=/var/zookeeper
clientPort=2181
配置kafka
/etc/kafka/server.properties
broker
.id=
0
auto
.create.topics.enable=true
# 自动创建topic
delete
.topic.enable=true
# 使删除topic命令可以起作用
host
.name=localhost
zookeeper
.connect=localhost:
2181
启动kafka server
> sudo zkServer
.sh start
> sudo kafka-server-start
.sh /etc/kafka/server
.properties # 可以加上-daemon选项在后台以守护进程运行
创建topic
>
-. -- -- --- -- -- -
获取topic列表
>
-. -- --
写消息到topic
>
--. --- -- -
从topic读取消息
> kafka
-console-consumer.sh
--zookeeper localhost:
2181 --topic test
-topic --from
-beginning
删除topic
>
-. -- -- -- - ...
参考文章
Kafka quickstartKafka0.8.2.x quickstart基于docker部署的微服务架构(五): docker环境下的zookeeper和kafka部署