简体   繁体   English

Kafka-python Producer执行Send,但Kafka没有数据到达

[英]Kafka-python Producer performs Send, but no data arrives in Kafka

I am attempting to send data to a Kafka topic via python as a remote producer.我正在尝试通过 python 作为远程生产者将数据发送到 Kafka 主题。 My script reports no exceptions, but nothing shows up in Kafka.我的脚本没有报告异常,但 Kafka 中没有显示任何内容。 I'm able to get a response from the brokers (all on one separate host) using the consumer method.我能够使用消费者方法从代理(都在一个单独的主机上)获得响应。 Looking through the forums I saw to make sure and flush the write cache, but no luck there.浏览我看到的论坛以确保并刷新写入缓存,但那里没有运气。 Script is below:脚本如下:

from kafka import KafkaProducer, KafkaConsumer
from json import dumps
producer = KafkaProducer(bootstrap_servers='192.168.1.100:9093', value_serializer=lambda x: dumps(x).encode('utf-8'))
producer.send('home-sensehat-temperature',{"timestamp": "2020-08-12 23:31:19.102347", "temperature": 127.6969})
producer.flush()
consumer=KafkaConsumer(bootstrap_servers='192.168.1.100:9093')
print(consumer.topics())

The response I get from consumer.topics() is: {'home-sensehat-temperature', 'home-camera-path', 'home-sensehat-humidity', 'home-sensehat-pressure'}我从 consumer.topics() 得到的响应是:{'home-sensehat-temperature', 'home-camera-path', 'home-sensehat-humidity', 'home-sensehat-pressure'}
So this implies I can make a good connection to the brokers.所以这意味着我可以与经纪人建立良好的联系。

I tried digging through the kafka broker logs but couldn't find anything.我尝试挖掘 kafka 代理日志,但找不到任何东西。 Any help would be greatly appreciated!任何帮助将不胜感激!

Got it, Everything was fine on the remote producer.明白了,远程制作人一切正常。 but I had to add a config parameter on the brokers.但我必须在代理上添加一个配置参数。 Specifically the advertised.listeners parameter in the config/server.properties file that each broker uses: Details are in the below post:特别是每个代理使用的 config/server.properties 文件中的 Advertisementd.listeners 参数:详细信息在以下帖子中:

Kafka: How to connect kafka-console-consumer to fetch remote broker topic content? Kafka:如何连接 kafka-console-consumer 以获取远程代理主题内容?

Thanks everyone!感谢大家!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM