Source:
public String createTopic(final NakadiTopicConfig nakadiTopicConfig) throws TopicCreationException { final KafkaTopicConfig kafkaTopicConfig = kafkaTopicConfigFactory.createKafkaTopicConfig(nakadiTopicConfig); try (AdminClient adminClient = AdminClient.create(kafkaLocationManager.getProperties())) { final NewTopic newTopic = TopicBuilder .name(kafkaTopicConfig.getTopicName()) .partitions(kafkaTopicConfig.getPartitionCount()) .replicas(kafkaTopicConfig.getReplicaFactor()) .configs(kafkaTopicConfigFactory.createKafkaTopicLevelProperties(kafkaTopicConfig)) .build(); adminClient.createTopics(Lists.newArrayList(newTopic)); } catch (final TopicExistsException e) { throw new TopicCreationException("Topic with name " + kafkaTopicConfig.getTopicName() + " already exists (or wasn't completely removed yet)", e); } catch (final Exception e) { throw new TopicCreationException("Unable to create topic " + kafkaTopicConfig.getTopicName(), e); } final long timeoutMillis = TimeUnit.SECONDS.toMillis(5); final Boolean allowsConsumption = Retryer.executeWithRetry(() -> { try (Consumer<byte[], byte[]> consumer = kafkaFactory.getConsumer()) { return null != consumer.partitionsFor(kafkaTopicConfig.getTopicName()); } }, new RetryForSpecifiedTimeStrategy<Boolean>(timeoutMillis) .withWaitBetweenEachTry(100L) .withResultsThatForceRetry(Boolean.FALSE)); if (!Boolean.TRUE.equals(allowsConsumption)) { throw new TopicCreationException("Failed to confirm topic creation within " + timeoutMillis + " millis"); } return kafkaTopicConfig.getTopicName(); }

Target:
public String createTopic(final NakadiTopicConfig nakadiTopicConfig) throws TopicCreationException { final KafkaTopicConfig kafkaTopicConfig = kafkaTopicConfigFactory.createKafkaTopicConfig(nakadiTopicConfig); try (AdminClient adminClient = AdminClient.create(kafkaLocationManager.getProperties())) { final NewTopic newTopic = TopicBuilder .name(kafkaTopicConfig.getTopicName()) .partitions(kafkaTopicConfig.getPartitionCount()) .replicas(kafkaTopicConfig.getReplicaFactor()) .configs(kafkaTopicConfigFactory.createKafkaTopicLevelProperties(kafkaTopicConfig)) .build(); adminClient.createTopics(Lists.newArrayList(newTopic)).all().get(30, TimeUnit.SECONDS); } catch (final TopicExistsException e) { throw new TopicCreationException("Topic with name " + kafkaTopicConfig.getTopicName() + " already exists (or wasn't completely removed yet)", e); } catch (final Exception e) { if (e instanceof InterruptedException) { Thread.currentThread().interrupt(); } throw new TopicCreationException("Unable to create topic " + kafkaTopicConfig.getTopicName(), e); } final long timeoutMillis = TimeUnit.SECONDS.toMillis(5); final Boolean allowsConsumption = Retryer.executeWithRetry(() -> { try (Consumer<byte[], byte[]> consumer = kafkaFactory.getConsumer()) { return null != consumer.partitionsFor(kafkaTopicConfig.getTopicName()); } }, new RetryForSpecifiedTimeStrategy<Boolean>(timeoutMillis) .withWaitBetweenEachTry(100L) .withResultsThatForceRetry(Boolean.FALSE)); if (!Boolean.TRUE.equals(allowsConsumption)) { throw new TopicCreationException("Failed to confirm topic creation within " + timeoutMillis + " millis"); } return kafkaTopicConfig.getTopicName(); }