'How to fix not receiving kafka messages in python but receiving the same messages in shell?

I want to consume messages coming in a kafka topic. I am using debezium which oplogs the mongodb changes and puts them in the kafka queue. I am able to connect to kafka using my python code, list the kafka topics. Although, when I want to consume the messages, its all blank whereas the same topic when consumed from the shell gives messages, performs perfectly.

from kafka import KafkaConsumer

topic = "dbserver1.inventory.customers"
# consumer = KafkaConsumer(topic, bootstrap_servers='localhost:9092', auto_offset_reset='earliest', auto_commit_enable=True)
consumer = KafkaConsumer(topic)
print("Consumer connected!")
# print("Topics are {}".format(consumer.topics()))
for message in consumer:
    print(message)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source