Kafka 0.8, is it possible to create topic with partition and replication using java code?

前端 未结 2 1826
野的像风
野的像风 2021-02-04 09:57

In Kafka 0.8beta a topic can be created using a command like below as mentioned here

    bin/kafka-create-topic.sh --zookeeper localhost:2181 --replica 2 --parti         


        
2条回答
  •  南方客
    南方客 (楼主)
    2021-02-04 10:49

    `

    import kafka.admin.AdminUtils;
    import kafka.cluster.Broker;
    import kafka.utils.ZKStringSerializer$;
    import kafka.utils.ZkUtils;
    
    String zkConnect = "localhost:2181";
    ZkClient zkClient = new ZkClient(zkConnect, 10 * 1000, 8 * 1000, ZKStringSerializer$.MODULE$);
    ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(zkConnect), false);
        Properties pop = new Properties();
        AdminUtils.createTopic(zkUtils, topic.getTopicName(), topic.getPartitionCount(), topic.getReplicationFactor(),
                pop);
        zkClient.close();`
    

提交回复
热议问题