問題如下:問題描述:ERROR Error when sending message to topic helloworld with key: null, value: 15 bytes with error: (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms.
小白剛接觸Kafka,所以全靠蒙解決了這個問題,記錄一下,如果你也和我一樣是個小白,碰到這個問題不妨試一下;
我的控制檯生產者語句:
bin/kafka-console-producer.sh --broker-list 192.168.1.130:9092 --topic test
控制檯消費者語句:
bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning
後來無意中發現我的conf/server.properties文件這麼寫的一句話:
# The address the socket server listens on. It will get the value returned from
# java.net.InetAddress.getCanonicalHostName() if not configured.
# FORMAT:
# listeners = security_protocol://host_name:port
# EXAMPLE:
listeners = PLAINTEXT://192.168.1.130:9092
#listeners=PLAINTEXT://:9092
注意看沒有註釋的地方: lip我配置爲本機虛擬機中的ip地址;
嘗試着將發送者語句改爲:
bin/kafka-console-producer.sh --broker-list 1.168.1.130:9092 --topic test
消費者就可以接收到消息了。
通過兩次實驗,發現一個奇淫巧技(我不能理解,以後明白了再回頭看啦,勿噴)? 控制檯發送者的broker-list的ip需要與server.properties中listeners處的一致,控制檯消費者就能接收到消息。