public void createTopic(String topicName, Integer numPartitions) { // setup String[] arguments = new String[9]; arguments[0] = "--create"; arguments[1] = "--zookeeper"; arguments[2] = zookeeperString; arguments[3] = "--replication-factor"; arguments[4] = "1"; arguments[5] = "--partitions"; arguments[6] = "" + Integer.valueOf(numPartitions); arguments[7] = "--topic"; arguments[8] = topicName; TopicCommand.TopicCommandOptions opts = new TopicCommand.TopicCommandOptions(arguments); /* // v0.9.0.1 ZkUtils zkUtils = ZkUtils.apply(opts.options().valueOf(opts.zkConnectOpt()), 30000, 30000, JaasUtils.isZkSecurityEnabled()); TopicCommand.createTopic(zkUtils, opts); */ // v0.8.2.1 ZkClient zkClient = new ZkClient(zookeeperString, 3000, 3000, ZKStringSerializer$.MODULE$); TopicCommand.createTopic(zkClient,opts); // run LOGGER.info("Executing: CreateTopic " + Arrays.toString(arguments)); }
public void createTopic(String topicName, Integer numPartitions) { // setup String[] arguments = new String[9]; arguments[0] = "--create"; arguments[1] = "--zookeeper"; arguments[2] = zookeeperString; arguments[3] = "--replication-factor"; arguments[4] = "1"; arguments[5] = "--partitions"; arguments[6] = "" + Integer.valueOf(numPartitions); arguments[7] = "--topic"; arguments[8] = topicName; TopicCommand.TopicCommandOptions opts = new TopicCommand.TopicCommandOptions(arguments); ZkUtils zkUtils = ZkUtils.apply(opts.options().valueOf(opts.zkConnectOpt()), 30000, 30000, JaasUtils.isZkSecurityEnabled()); // run LOGGER.info("Executing: CreateTopic " + Arrays.toString(arguments)); TopicCommand.createTopic(zkUtils, opts); }
public static void createTopic(String kafkaTopic, String zkStr) { // TopicCommand.main() will call System.exit() finally, which will break maven-surefire-plugin try { String[] args = new String[]{"--create", "--zookeeper", zkStr, "--replication-factor", "1", "--partitions", "1", "--topic", kafkaTopic}; KafkaZkClient zkClient = KafkaZkClient.apply(zkStr, false, 30000, 30000, Integer.MAX_VALUE, Time.SYSTEM,"kafka.server", "SessionExpireListener"); TopicCommand.TopicCommandOptions opts = new TopicCommand.TopicCommandOptions(args); TopicCommand.createTopic(zkClient, opts); } catch (TopicExistsException e) { // Catch TopicExistsException otherwise it will break maven-surefire-plugin System.out.println("Topic already existed"); } } }
public static void createTopic(String kafkaTopic, String zkStr) { // TopicCommand.main() will call System.exit() finally, which will break maven-surefire-plugin try { String[] args = new String[]{"--create", "--zookeeper", zkStr, "--replication-factor", "1", "--partitions", "1", "--topic", kafkaTopic}; KafkaZkClient zkClient = KafkaZkClient.apply(zkStr, false, 30000, 30000, Integer.MAX_VALUE, Time.SYSTEM,"kafka.server", "SessionExpireListener"); TopicCommand.TopicCommandOptions opts = new TopicCommand.TopicCommandOptions(args); TopicCommand.createTopic(zkClient, opts); } catch (TopicExistsException e) { // Catch TopicExistsException otherwise it will break maven-surefire-plugin System.out.println("Topic already existed"); } } }
public void createTopic(String topicName, int numPartitions) { // setup String[] arguments = new String[9]; arguments[0] = "--create"; arguments[1] = "--zookeeper"; arguments[2] = zookeeperString; arguments[3] = "--replication-factor"; arguments[4] = "1"; arguments[5] = "--partitions"; arguments[6] = String.valueOf(numPartitions); arguments[7] = "--topic"; arguments[8] = topicName; TopicCommand.TopicCommandOptions opts = new TopicCommand.TopicCommandOptions(arguments); ZkUtils zkUtils = ZkUtils.apply(opts.options().valueOf(opts.zkConnectOpt()), 30000, 30000, JaasUtils.isZkSecurityEnabled()); try{ // run LOGGER.info("Executing: CreateTopic " + Arrays.toString(arguments)); TopicCommand.createTopic(zkUtils, opts); } finally { zkUtils.close(); } }
public static void createTopic(String kafkaTopic, String zkStr) { // TopicCommand.main() will call System.exit() finally, which will break maven-surefire-plugin try { String[] args = new String[]{"--create", "--zookeeper", zkStr, "--replication-factor", "1", "--partitions", "1", "--topic", kafkaTopic}; KafkaZkClient zkClient = KafkaZkClient.apply(zkStr, false, 30000, 30000, Integer.MAX_VALUE, Time.SYSTEM,"kafka.server", "SessionExpireListener"); TopicCommand.TopicCommandOptions opts = new TopicCommand.TopicCommandOptions(args); TopicCommand.createTopic(zkClient, opts); } catch (TopicExistsException e) { // Catch TopicExistsException otherwise it will break maven-surefire-plugin System.out.println("Topic already existed"); } } }
public void createTopic(int clusterid, String topicName) { String[] args = new String[9]; args[0] = "--zookeeper"; args[1] = "localhost:" + TEST_ZOOKEEPER_PORT[clusterid]; args[2] = "--replication-factor"; args[3] = "1"; args[4] = "--partitions"; if (hasMultiPartition) { args[5] = "2"; } else { args[5] = "1"; } args[6] = "--topic"; args[7] = topicName; args[8] = "--create"; ZkUtils zu = ZkUtils.apply("localhost:" + TEST_ZOOKEEPER_PORT[clusterid], 30000, 30000, false); TopicCommand.createTopic(zu, new TopicCommand.TopicCommandOptions(args)); }
public void createTopic(int clusterid, String topicName) { String[] args = new String[9]; args[0] = "--zookeeper"; args[1] = "localhost:" + TEST_ZOOKEEPER_PORT[clusterid]; args[2] = "--replication-factor"; args[3] = "1"; args[4] = "--partitions"; if (hasMultiPartition) { args[5] = "2"; } else { args[5] = "1"; } args[6] = "--topic"; args[7] = topicName; args[8] = "--create"; ZkUtils zu = ZkUtils.apply("localhost:" + TEST_ZOOKEEPER_PORT[clusterid], 30000, 30000, false); TopicCommand.createTopic(zu, new TopicCommand.TopicCommandOptions(args)); }
TopicCommand.createTopic( zkUtils, new TopicCommand.TopicCommandOptions(argsList.stream().toArray(String[]::new)));