python读取Kafka实例
时间:2022-02-11 10:01:47|栏目:Python代码|点击: 次
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. 执行结果