java spring-boot kafka create topic

java spring-boot kafka create topic

        Map<String, Object> configs = new HashMap<>();
        configs.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG,
                "10.200.4.92:9092,10.200.4.93:9092,10.200.4.94:9092");
        KafkaAdmin admin = new KafkaAdmin(configs);

        NewTopic newTopic = new NewTopic("foo2", 1, (short) 1);

        AdminClient adminClient = AdminClient.create(admin.getConfig());
        List<NewTopic> topicList = Arrays.asList(newTopic);
        adminClient.createTopics(topicList);

        adminClient.close(10, TimeUnit.SECONDS);

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324391850&siteId=291194637