scala Kafka 主题创建:等待节点分配超时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/53586130/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 09:37:16  来源:igfitidea点击:

Kafka topic creation: Timed out waiting for a node assignment

scaladockerapache-kafka

提问by Milan

Ive got a local kafka running using the following docker-compose.yml

我已经使用以下 docker-compose.yml 运行了本地 kafka

version: '2'
services:
  zookeeper:
    image: "confluentinc/cp-zookeeper:5.0.1"
    environment:
      ZOOKEEPER_CLIENT_PORT: 2181
      ZOOKEEPER_TICK_TIME: 2000

  kafka:
    image: "confluentinc/cp-enterprise-kafka:5.0.1"
    ports:
      - '9092:9092'
    depends_on:
      - zookeeper
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
      KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092
      KAFKA_METRIC_REPORTERS: io.confluent.metrics.reporter.ConfluentMetricsReporter
      KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 100

Trying to run a basic create topic using kafka-client 2.1.0 in Scala:

尝试在 Scala 中使用 kafka-client 2.1.0 运行基本的创建主题:

val props = new Properties()
props.setProperty(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092")

val adminClient: AdminClient = AdminClient.create(props)
val newTopic = new NewTopic("test", 1, 1.toShort)
val topicsF = adminClient.createTopics(List(newTopic).asJavaCollection)
val result = topicsF.all().get()

but after some time I get:

但一段时间后我得到:

org.apache.kafka.common.errors.TimeoutException: Timed out waiting for a node assignment.

I can create a topic using the command line:

我可以使用命令行创建主题:

kafka-topics --create \
    --zookeeper localhost:2181 \
    --replication-factor 1 \
    --partitions 1 \
    --topic test
Created topic "test".

kafka AdminClient API Timed out waiting for node assignmentdescribes a similar problem using Java but the comment suggests that a system restart fixed the issue which is not the case on my side.

kafka AdminClient API Timed out waiting for node assignment描述了一个使用 Java 的类似问题,但评论表明系统重启解决了这个问题,而我这边的情况并非如此。

采纳答案by Robin Moffatt

If you're running Kafka in Docker (or similar) you need to configure the listeners correctly. This articledescribes it in detail.

如果您在 Docker(或类似)中运行 Kafka,则需要正确配置侦听器。本文对其进行了详细介绍。

Here's an exampleof a Docker Compose that you can use to access Kafka from your host machine.

是一个 Docker Compose示例,您可以使用它从主机访问 Kafka。

Disclaimer: I wrote the article :)

免责声明:我写了这篇文章:)

回答by Bitswazsky

I think the localhostis the problem. In your bootstrap-serversproperties use the advertised host (192.168.99.100) that you've defined in your compose file, instead of localhost, that should work.

我认为这localhost是问题所在。在您的bootstrap-servers属性中,使用您在撰写文件中定义的广告主机 (192.168.99.100) 而不是localhost,它应该可以工作。