KafkaTimeoutError(“ 60.0秒后无法更新元数据。”)

时间:2019-01-20 11:24:54

标签: python apache-kafka kafka-python

我正在使用Python 3.6编写Kafka生产者,Python-kafka客户端版本为1.4.4。Kafka版本为:2.1.0和1.1.1(尝试了两个版本),但是当我向生产者,抛出此错误:

KafkaTimeoutError('Failed to update metadata after 60.0 secs.')

这是我的客户代码:

producer = KafkaProducer(
  bootstrap_servers=['mq-server:9092'],
  api_version = (0,10,2,0) # solve no broker error
)

producer.send("dolphin-test".encode('utf-8'),b"test")

这是我修改过的服务器配置:

listeners=PLAINTEXT://10.142.0.2:9092
advertised.listeners=PLAINTEXT://10.142.0.2:9092

使用脚本生成和使用消息时,它工作正常!这是客户端跟踪输出:

D:\project\souce\pydolphin-service>D:/Programs/Python/Python37/python.exe d:/project/souce/pydolphin-service/dolphin/producer.py
Traceback (most recent call last):
  File "d:/project/souce/pydolphin-service/dolphin/producer.py", line 14, in <module>
    future = producer.send('my-topic', b'raw_bytes')
  File "D:\Programs\Python\Python37\lib\site-packages\kafka\producer\kafka.py", line 555, in send
    self._wait_on_metadata(topic, self.config['max_block_ms'] / 1000.0)
  File "D:\Programs\Python\Python37\lib\site-packages\kafka\producer\kafka.py", line 682, in _wait_on_metadata
    "Failed to update metadata after %.1f secs." % (max_wait,))
kafka.errors.KafkaTimeoutError: KafkaTimeoutError: Failed to update metadata after 60.0 secs.

我在Google,百度和yandex中搜索。

2 个答案:

答案 0 :(得分:2)

您的开发箱和kafka服务器是否有防火墙。您能尝试telnet mq-server 9092

答案 1 :(得分:0)

调整广告配置:

advertised.listeners=PLAINTEXT://external-ip:9092

将NAT内部网络ip修改为公共网络ip 。因为生产者会将消息发送到该地址。生产者只能与公众接触。