“kafka.zookeeper.ZooKeeperClientTimeoutException:等待连接超时"仅在上市主题期间 [英] "kafka.zookeeper.ZooKeeperClientTimeoutException: Timed out waiting for connection" ONLY DURING LISTING TOPICS

查看:28
本文介绍了“kafka.zookeeper.ZooKeeperClientTimeoutException:等待连接超时"仅在上市主题期间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了几个主题相似但上下文不同的问题:我可以连接以创建主题,但我无法列出主题,因为我收到了下面提到的错误(据我所知,人们面临着基本问题连接时我只是为了列出主题列表).

I found few questions with similar topic but different context: I can connect to create a Topic but I can't list the topics because I got the error mentioned below (as far as I could see, people were facing issues for basic connecting while I am getting only for listing the topic list).

以防万一,这是我的docker-compose.yml:

version: "3"
services:
    zookeeper:
        image: wurstmeister/zookeeper

    kafka:
        image: wurstmeister/kafka
        ports:
            - "9092:9092"
        environment:
            KAFKA_ADVERTISED_HOST_NAME: "localhost"
            KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"

我的控制台:

bash-4.4# kafka-topics.sh --create --zookeeper zookeeper:2181 --replication-factor 1 --partitions 1 --topic test2
Created topic test2.
bash-4.4# kafka-topics.sh --list --zookeeper localhost:2181
Exception in thread "main" kafka.zookeeper.ZooKeeperClientTimeoutException: Timed out waiting for connection while in state: CONNECTING
        at kafka.zookeeper.ZooKeeperClient.$anonfun$waitUntilConnected$3(ZooKeeperClient.scala:259)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
        at kafka.utils.CoreUtils$.inLock(CoreUtils.scala:253)
        at kafka.zookeeper.ZooKeeperClient.waitUntilConnected(ZooKeeperClient.scala:255)
        at kafka.zookeeper.ZooKeeperClient.<init>(ZooKeeperClient.scala:113)
        at kafka.zk.KafkaZkClient$.apply(KafkaZkClient.scala:1858)
        at kafka.admin.TopicCommand$ZookeeperTopicService$.apply(TopicCommand.scala:321)
        at kafka.admin.TopicCommand$.main(TopicCommand.scala:54)
        at kafka.admin.TopicCommand.main(TopicCommand.scala)
bash-4.4# kafka-topics.sh --create --zookeeper zookeeper:2181 --replication-factor 1 --partitions 1 --topic test3
Created topic test3.
bash-4.4# kafka-topics.sh --list --zookeeper localhost:2181
Exception in thread "main" kafka.zookeeper.ZooKeeperClientTimeoutException: Timed out waiting for connection while in state: CONNECTING
        at kafka.zookeeper.ZooKeeperClient.$anonfun$waitUntilConnected$3(ZooKeeperClient.scala:259)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
        at kafka.utils.CoreUtils$.inLock(CoreUtils.scala:253)
        at kafka.zookeeper.ZooKeeperClient.waitUntilConnected(ZooKeeperClient.scala:255)
        at kafka.zookeeper.ZooKeeperClient.<init>(ZooKeeperClient.scala:113)
        at kafka.zk.KafkaZkClient$.apply(KafkaZkClient.scala:1858)
        at kafka.admin.TopicCommand$ZookeeperTopicService$.apply(TopicCommand.scala:321)
        at kafka.admin.TopicCommand$.main(TopicCommand.scala:54)
        at kafka.admin.TopicCommand.main(TopicCommand.scala)
bash-4.4#

已编辑

未来的读者可能会发现我可以直接从我的 Docker Kafka 容器列出所有主题而无需登录我的 Docker Zookeper 容器(https)很有用://stackoverflow.com/a/56595227/4148175)

C:\Users\>docker exec -it test1_kafka_1 bash

bash-4.4# kafka-topics.sh --list --bootstrap-server localhost:9092
__consumer_offsets
test2
test3
test_topic
bash-4.4# 

推荐答案

--zookeeper zookeeper:2181 似乎工作正常

--zookeeper localhost:2181 在 kafka 容器内总是会失败,因为它没有运行 Zookeeper 服务器

--zookeeper localhost:2181 will always fail inside the kafka container because it's not running a zookeeper server

注意:最新的 kafka 版本支持使用 --bootstrap-server 代替,因此您可以使用 kafka 容器中的 kafka:9092 localhost:9092

这篇关于“kafka.zookeeper.ZooKeeperClientTimeoutException:等待连接超时"仅在上市主题期间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆