I have a setup of Debezium which uses Kafka. I am able to consume messages from kafka console as described in the doc. However, when I create a kafka consumer using Python on my local, I am unable to consume messages. It should be noted that kafka console works just fine!
I tried looking into this issue but was unable to have similar environments/situations
My python code to connect is:
from kafka import KafkaConsumer
consumer = KafkaConsumer('dbserver1.inventory.customers', group_id='my-group', bootstrap_servers=['localhost:9092'], auto_offset_reset='earliest')
for message in consumer:
print(message)
This just goes blank regardless of existing messages or new messages pushed to this topic.
I am sure that the messages exist because when I open up a console consumer, I get to see the messages.
Just to be clear on the whole setup:
I have followed this (https://github.com/debezium/debezium-examples/tree/master/tutorial#using-mongodb) doc for each step(except the last one).
Everything works but my Python code.
I also tried creating a consumer with kafka:9092
bootstrap server but it ends up in an error:
kafka.errors.NoBrokersAvailable: NoBrokersAvailable
My local is Mac OS.
FYI: I am able to get everything else, like topics:
>>> consumer = KafkaConsumer('dbserver1.inventory.customers', group_id='my-group', bootstrap_servers=['localhost:9092'], auto_offset_reset='earliest')
>>> consumer.topics()
{'my_connect_offsets', 'my_connect_configs', 'dbserver1.inventory.orders', 'connect-status', 'dbserver1.inventory.customers', 'dbserver1.inventory.products'}
I am starting consumer via command:
docker-compose -f debezium-mongodb.yaml exec kafka /kafka/bin/kafka-console-consumer.sh \
--bootstrap-server kafka:9092 \
--from-beginning \
--property print.key=true \
--topic dbserver1.inventory.customers