
正文
python访问kafka
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
操作系统 : CentOS7.3.1611_x64
Python 版本 : 3.6.8
kafka 版本 : 2.3.1
本文记录python访问kafka的简单使用,是入门教程,高阶读者请直接忽略。
下载并启动kafka
kafka官方网址: http://kafka.apache.org/
下载并解压kafka :
http://mirrors.tuna.tsinghua.edu.cn/apache/kafka/2.3.1/kafka_2.12-2.3.1.tgz
tar zxvf kafka_2.-2.3..tgz
cd kafka_2.-2.3./
启动zookeeper:
bin/zookeeper-server-start.sh config/zookeeper.properties
启动kafka :
bin/kafka-server-start.sh config/server.properties
控制台测试:
bin/kafka-console-producer.sh --broker-list localhost: --topic test bin/kafka-console-consumer.sh --bootstrap-server localhost: --topic test --from-beginning
使用python访问kafka
安装依赖库:
pip install kafka
Producer示例代码:
https://github.com/mike-zhang/pyExamples/blob/master/mqOpt/kafkaTest1/producerTest1.py
Consumer示例代码:
https://github.com/mike-zhang/pyExamples/blob/master/mqOpt/kafkaTest1/consumerTest1.py
本文github地址:
https://github.com/mike-zhang/mikeBlogEssays/blob/master/2019/20191128_python访问kafka.rst
欢迎补充




