Files
100-Days-Of-ML-Code/Code/TestKafka.py
2019-05-07 16:10:45 +08:00

24 lines
822 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/python
from kafka import KafkaConsumer;
kafkaHosts=["kafka01.paas.longfor.sit:9092"
,"kafka02.paas.longfor.sit:9092"
,"kafka03.paas.longfor.sit:9092"]
'''
earliest
当各分区下有已提交的offset时从提交的offset开始消费无提交的offset时从头开始消费
latest
当各分区下有已提交的offset时从提交的offset开始消费无提交的offset时消费新产生的该分区下的数据
none
topic各分区都存在已提交的offset时从offset后开始消费只要有一个分区不存在已提交的offset则抛出异常
'''
consumer = KafkaConsumer(
bootstrap_servers=kafkaHosts,group_id='mdf_group',auto_offset_reset='latest');
consumer.subscribe("testapplog_plm-prototype");
for msg in consumer:
print(msg.value)