From 31405d08bc8c45170cf1bea1de3524b946a466a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Sat, 24 Apr 2021 20:12:01 +0200 Subject: [PATCH] kafka consumer --- kafka/consumer.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/kafka/consumer.py b/kafka/consumer.py index ac8d83d..b0d45af 100644 --- a/kafka/consumer.py +++ b/kafka/consumer.py @@ -1,3 +1,21 @@ #!/usr/bin/env python3 from datetime import datetime +from kafka import KafkaConsumer + + +DATETIMES=[] + + +consumer = KafkaConsumer(bootstrap_servers='localhost:9092', auto_offset_reset='earliest', consumer_timeout_ms=1000) +consumer.subscribe(['test']) + + +try: + while True: + for message in consumer: + DATETIMES.append(datetime.now()) + consumer.close() +except Exception: + consumer.close() + print(DATETIMES)