【发布时间】:2019-09-17 18:58:22
【问题描述】:
我有一个使用 Kafka 的 Debezium 设置。如文档中所述,我可以使用来自 kafka 控制台的消息。但是,当我在本地使用 Python 创建 kafka 消费者时,我无法使用消息。需要注意的是,kafka 控制台工作正常!
我尝试调查此问题,但无法找到类似的环境/情况
我要连接的python代码是:
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)
无论现有消息或推送到此主题的新消息如何,这都会变为空白。
我确信消息存在,因为当我打开控制台使用者时,我可以看到消息。
只是为了清楚整个设置:
对于每个步骤(最后一步除外),我都遵循了这个 (https://github.com/debezium/debezium-examples/tree/master/tutorial#using-mongodb) 文档。
一切正常,但我的 Python 代码。
我还尝试使用kafka:9092 引导服务器创建消费者,但最终出现错误:
kafka.errors.NoBrokersAvailable: NoBrokersAvailable
我的本地是 Mac OS。
仅供参考: 我可以获得其他所有内容,例如主题:
>>> 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'}
我正在通过命令启动消费者:
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
【问题讨论】:
-
您能否发布您的控制台消费者,您可以使用它成功地消费消息。
-
@GokulPotluri,完成!
标签: python python-3.x apache-kafka kafka-consumer-api debezium