from kafka import KafkaProducer
log_path="log.txt"
bootstrap_servers = 'localhost:9092'
producer = KafkaProducer(bootstrap_servers=bootstrap_servers,acks='1')
##此处监控获取文件的修改,后续改为flume
def produce(path):
point = 0
while True:
with open(log_path,'r',encoding='utf-8') as f:
f.seek(point)
for line in f:
print(line)
producer.send(topic="txt_test",value=line.encode('utf-8'))
point = f.tell()
f.close()
if __name__ == "__main__":
produce(log_path)
网友评论