python读取Kafka实例
1. 新建.py文件
# pip install kafka-python from kafka import KafkaConsumer import setting conf = setting.luyang_kafka_setting consumer = KafkaConsumer(bootstrap_servers=conf['host'], group_id=conf['groupid']) print('consumer start to consuming...') consumer.subscribe((conf['topic'], )) for message in consumer: print(message.topic, message.offset, message.key, message.value, message.value, message.partition)
以上是kafka主要程序
2. Kafka配置文件setting.py
luyang_kafka_setting = { 'host':'0.0.0.0:9092', 'topic':'zcfTest', 'groupid':'luyang1' }
配置如上
3. 执行结果
以上这篇python读取Kafka实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。