我试着用卡夫卡。 所有配置都正确完成,但当我试图从控制台产生消息时,我一直得到以下错误

WARN Error while fetching metadata with correlation id 39 : 
     {4-3-16-topic1=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)

Kafka版本:2.11-0.9.0.0


当前回答

For all those struggling with the Kafka ssl setup and seeing this LEADER_NOT_AVAILABLE error. One of the reasons that might be broken is the keystore and truststore. In the keystore you need to have private key of the server + signed server certificate. In the client truststore, you need to have intermedidate CA certificate so that client can authenticate the kafka server. If you will use ssl for interbroker communication, you need this truststore also set in the server.properties of the brokers so they can authenticate each other.

我错误地漏掉了最后一篇文章,这让我痛苦地花了很多时间去寻找这个LEADER_NOT_AVAILABLE错误可能意味着什么。希望这能帮助到一些人。

其他回答

上述答案中提到的广告听众可能是原因之一。其他可能的原因有:

主题可能还没有创建。你可以使用bin/kafka-topics——list——zookeeper <zookeeper ip>:<zookeeper port>来检查 检查您提供给生成器以获取元数据的引导服务器。如果引导服务器不包含关于主题的最新元数据(例如,当它丢失其zookeeper声明时)。您必须添加多个引导服务器。

另外,确保已将所发布的侦听器设置为IP:9092而不是localhost:9092。后者意味着只能通过本地主机访问代理。

当我遇到错误时,我记得在引导服务器(或代理列表)列表中使用了PLAINTEXT://<ip>:<PORT>,它工作了,奇怪的是。

bin/kafka-console-producer --topic sample --broker-list PLAINTEXT://<IP>:<PORT>

这是我在config/server中添加的。属性,这解决了我的问题类似上述问题。希望这有助于,它在服务器中有很好的文档。属性文件,在修改此文件之前,请尝试阅读和理解。 advertised.listeners =明文:/ / < your_kafka_server_ip >: 9092

我使用的是kafka_2.12-0.10.2.1:

vi problem / server . properties

加到下面一行:

listeners=PLAINTEXT://localhost:9092

不需要更改广告。当它拾取值时监听器 从STD侦听器属性。

代理将向生产者和消费者发布主机名和端口。如果没有设置,

如果配置了“监听器”,则使用该值

否则,它将使用从java.net.InetAddress.getCanonicalHostName()返回的值。

停止Kafka代理:

bin/kafka-server-stop.sh

重新启动代理:

bin/kafka-server-start.sh -daemon config/server.properties

现在你应该不会看到任何问题。

我使用docker-compose来构建使用wurstmeister/ Kafka映像的Kafka容器。在docker-compose文件中添加KAFKA_ADVERTISED_PORT: 9092属性为我解决了这个错误。

试试这个监听器=PLAINTEXT://localhost:9092 一定很有帮助

非常感谢