-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathkafka_consumer.py
More file actions
24 lines (19 loc) · 796 Bytes
/
kafka_consumer.py
File metadata and controls
24 lines (19 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import argparse
from kafka import KafkaConsumer
parser = argparse.ArgumentParser()
# Pass user registered phone no as an argument to fetch message from producer
parser.add_argument('-p', '--participant')
if __name__ == '__main__':
args = parser.parse_args()
if args.participants:
phone_no = args.participants
consumer = KafkaConsumer(
phone_no,
bootstrap_servers=['localhost:9092'],
auto_offset_reset='earliest',
enable_auto_commit=True)
# In case of group conversation, client needs to subscribed the consumers to a particular topic (i.e. Group Name)
group_topic = 'KAFKA_TOPIC_NAME_GOES_HERE'
consumer.subscribe(group_topic)
for m in consumer:
print('{}'.format(m.value))