kafka AdminClient API Timed out waiting for node assignment

前端 未结 2 679
挽巷
挽巷 2021-02-19 07:47

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

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-19 08:07

    Sounds like your broker isn't healthy...

    This code works fine

    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

提交回复
热议问题