kafka AdminClient API 等待节点分配超时 [英] kafka AdminClient API Timed out waiting for node assignment

查看:74
本文介绍了kafka AdminClient API 等待节点分配超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Kafka 的新手,正在尝试使用 AdminClient API 来管理在我的本地机器上运行的 Kafka 服务器.我的设置与 Kafka 文档的 quick start 部分完全相同.唯一的区别是我没有创建任何主题.

I'm new to Kafka and am trying to use the AdminClient API to manage the Kafka server running on my local machine. I have it setup exactly the same as in the quick start section of the Kafka documentation. The only difference being that I have not created any topics.

我在此设置上运行任何 shell 脚本都没有问题,但是当我尝试运行以下 Java 代码时:

I have no issues running any of the shell scripts on this setup but when I try to run the following java code:

public class ProducerMain{

    public static void main(String[] args) {
        Properties props = new Properties();
        props.setProperty(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, 
            "localhost:9092");


        try(final AdminClient adminClient = 
              KafkaAdminClient.create(props)){

            try {
                final NewTopic newTopic = new NewTopic("test", 1, 
                    (short)1);

                final CreateTopicsResult createTopicsResult = 
                    adminClient.createTopics( 
                         Collections.singleton(newTopic));

                createTopicsResult.all().get();

            }catch (InterruptedException | ExecutionException e) {
                e.printStackTrace();
            }
        }
    }
}

错误:TimeoutException:等待节点分配超时

Exception in thread "main" java.lang.RuntimeException: org.apache.kafka.common.errors.TimeoutException: Timed out waiting for a node assignment.
at ProducerMain.main(ProducerMain.java:41)
    <br>Caused by: java.util.concurrent.ExecutionException: org.apache.kafka.common.errors.TimeoutException: Timed out waiting for a node assignment.
at org.apache.kafka.common.internals.KafkaFutureImpl.wrapAndThrow(KafkaFutureImpl.java:45)
at org.apache.kafka.common.internals.KafkaFutureImpl.access$000(KafkaFutureImpl.java:32)
at org.apache.kafka.common.internals.KafkaFutureImpl$SingleWaiter.await(KafkaFutureImpl.java:89)
at org.apache.kafka.common.internals.KafkaFutureImpl.get(KafkaFutureImpl.java:258)
at ProducerMain.main(ProducerMain.java:38)
<br>Caused by: org.apache.kafka.common.errors.TimeoutException: Timed out waiting for a node assignment.

我已在网上搜索有关问题可能是什么的指示,但到目前为止一无所获.欢迎提出任何建议,因为我已经走到尽头了.

I have searched online for an indication as to what the problem could be but have found nothing so far. Any suggestions are welcome as I am at the end of my rope.

推荐答案

听起来你的经纪人不健康...

Sounds like your broker isn't healthy...

此代码工作正常

public class Main {

    static final Logger logger = LoggerFactory.getLogger(Main.class);

    public static void main(String[] args) {
        Properties properties = new Properties();
        properties.setProperty(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
        properties.setProperty(AdminClientConfig.CLIENT_ID_CONFIG, "local-test");
        properties.setProperty(AdminClientConfig.RETRIES_CONFIG, "3");

        try (AdminClient client = AdminClient.create(properties)) {
            final CreateTopicsResult res = client.createTopics(
                    Collections.singletonList(
                            new NewTopic("foo", 1, (short) 1)
                    )
            );
            res.all().get(5, TimeUnit.SECONDS);
        } catch (InterruptedException | ExecutionException | TimeoutException e) {
            logger.error("unable to create topic", e);
        }
    }
}

我可以在代理日志中看到该主题已创建

And I can see in the broker logs that the topic was created

这篇关于kafka AdminClient API 等待节点分配超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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