/** * @param zkServers Zookeeper server string: host1:port1[,host2:port2,...] * @param topic topic to create (if not already existing) * @param partitions number of topic partitions */ public static void maybeCreateTopic(String zkServers, String topic, int partitions) { maybeCreateTopic(zkServers, topic, partitions, new Properties()); }
protected final void startMessaging() throws IOException, InterruptedException { log.info("Starting local test Zookeeper server"); localZKServer = new LocalZKServer(localZKPort); localZKServer.start(); log.info("Starting local Kafka broker"); localKafkaBroker = new LocalKafkaBroker(localKafkaBrokerPort, localZKPort); localKafkaBroker.start(); String zkHostPort = "localhost:" + localZKPort; KafkaUtils.deleteTopic(zkHostPort, INPUT_TOPIC); KafkaUtils.deleteTopic(zkHostPort, UPDATE_TOPIC); KafkaUtils.maybeCreateTopic(zkHostPort, INPUT_TOPIC, 1); KafkaUtils.maybeCreateTopic(zkHostPort, UPDATE_TOPIC, 1); // Give topics a little time to elect leader try { Thread.sleep(5000); } catch (InterruptedException ie) { // continue } }
KafkaUtils.maybeCreateTopic(zkHostPort, TOPIC, 4);
KafkaUtils.maybeCreateTopic(zkHostPort, TOPIC, 1, ConfigUtils.keyValueToProperties( "max.message.bytes", maxMessageSize ));
/** * @param zkServers Zookeeper server string: host1:port1[,host2:port2,...] * @param topic topic to create (if not already existing) * @param partitions number of topic partitions */ public static void maybeCreateTopic(String zkServers, String topic, int partitions) { maybeCreateTopic(zkServers, topic, partitions, new Properties()); }