@phper
2017-05-27T18:09:34.000000Z
字数 1968
阅读 4002
Kafka
kafka是目前的一个主流,它在处理消息队列、异步落地、订阅分发等领域都处于主流,今天来学习一下kafka。
kafka是一个Java服务,依赖于Java。如果,你的机器上没有安装java ,那么需要下下载安装:
Java jdk-8u131-linux-x64.tar.gz 下载:
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz
然后解压到/usr/local/jdk/下。
然后打开/etc/profile文件
[root@localhost ~]# vim /etc/profile
把下面这段代码写到文件里
export JAVA_HOME=/usr/local/jdk/jdk1.8.0_131
export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
export PATH=$JAVA_HOME/bin:$PATH
最后source生效下。
[root@localhost ~]# source /etc/profile
kafka kafka_2.12-0.10.2.1.tgz下载:
https://www.apache.org/dyn/closer.cgi?path=/kafka/0.10.2.1/kafka_2.12-0.10.2.1.tgz
https://mirrors.tuna.tsinghua.edu.cn/apache/kafka/0.10.2.1/kafka_2.12-0.10.2.1.tgz
解压到 /usr/local/kafka/kafka_2.12-0.10.2.1
Kafka用到了Zookeeper,所有首先启动Zookper,下面简单的启用一个单实例的Zookkeeper服务。可以在命令的结尾加个&符号,这样就可以启动后离开控制台。
sh bin/zookeeper-server-start.sh config/zookeeper.properties &
[1] 6501
[root@web3 kafka_2.12-0.10.2.1]# [2017-05-15 02:41:44,770] INFO Reading configuration from: config/zookeeper.properties (org.apache.zookeeper.server.quorum.QuorumPeerConfig)
[2017-05-15 02:41:44,785] INFO autopurge.snapRetainCount set to 3 (org.apache.zookeeper.server.DatadirCleanupManager)
[2017-05-15 02:41:44,785] INFO autopurge.purgeInterval set to 0 (org.apache.zookeeper.server.DatadirCleanupManager)
[2017-05-15 02:41:44,786] INFO Purge task is not scheduled. (org.apache.zookeeper.server.DatadirCleanupManager)
sh bin/kafka-server-start.sh config/server.properties &
启动生产者:
sh bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
启动消费者:
bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning
在生产者的命令行窗口,输入文字,在消费者窗口就能看到这个消息了。
http://www.bkjia.com/PHPjc/1100706.html
https://github.com/weiboad/kafka-php
http://www.cnblogs.com/the-tops/p/5685955.html
http://www.orchome.com/kafka/index