I have to listen to a topic on Kafka and consume the messages being published on it. My piece of code is working fine but sometimes gets stuck in the try block as poll returns empty dictionary.
Please suggest a better way to poll the topic. TIA!
consumer = KafkaConsumer(**consumer_configs)
consumer.subscribe(topics=[topic_name])
while True:
try:
records = consumer.poll(10000, 500)
for message in records.values():
for msg in message:
print(msg.value)