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

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


当前回答

我知道这是很久以前发布的,我想分享我是如何解决它的。 因为我有我的办公室笔记本电脑(VPN和代理配置)。 我检查了环境变量NO_PROXY

> echo %NO_PROXY%

返回空值 现在我已经设置了NO_PROXY与localhost和127.0.0.1

> set NO_PROXY=127.0.0.1,localhost  

如果您想追加现有值,则

> set NO_PROXY=%NO_PROXY%,127.0.0.1,localhost  

在这之后,我重新启动了zookeeper和kafka 工作起来很有魅力

其他回答

加上这个,因为它可能会帮助其他人。一个常见的问题可能是advertised.host.name配置错误。在Docker中,使用Docker -compose设置KAFKA_ADVERTISED_HOST_NAME中的服务名称将不起作用,除非你也设置了主机名。docker-compose。yml例子:

  kafka:
    image: wurstmeister/kafka
    ports:
      - "9092:9092"
    hostname: kafka
    environment:
      KAFKA_ADVERTISED_HOST_NAME: kafka
      KAFKA_CREATE_TOPICS: "test:1:1"
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

上面没有hostname: kafka可以在尝试连接时发出一个LEADER_NOT_AVAILABLE。 您可以在这里找到一个工作docker-compose配置的示例

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错误可能意味着什么。希望这能帮助到一些人。

如果你在本地机器上运行kafka,尝试更新$KAFKA_DIR/config/server。以下行包含的属性: //localhost:9092然后重启kafka。

当我们试图订阅一个尚未创建的主题时,我们往往会收到这条消息。我们通常依赖于在部署环境中预先创建的主题,但我们有针对dockerized kafka实例运行的组件测试,每次都干净启动。

在这种情况下,我们在测试设置中使用AdminUtils来检查主题是否存在,如果不存在就创建它。有关设置AdminUtils的更多信息,请参阅另一个堆栈溢出。

我使用的是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

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