only try to create topics if there are topics to be created

This commit is contained in:
Adam 2022-01-25 00:11:38 +01:00
parent dbeb0e73dd
commit 4fc55b706f

View file

@ -30,6 +30,8 @@ object CreateTopics {
KafkatorioPacket.PacketType.values().forEach { packetType ->
val currentTopics = currentTopics().map { it.name() }
val kafkatorioTopics = buildSet {
add(KafkatorioTopology.sourceTopic)
when (packetType) {
@ -42,16 +44,12 @@ object CreateTopics {
KafkatorioPacket.PacketType.PROTOTYPES ->
add("kafkatorio.${packetType.name}.all")
}
}
}.minus(currentTopics.toSet())
val currentTopics = currentTopics().map { it.name() }
if (currentTopics.isNotEmpty()) {
val result = kafkatorioTopics
.filterNot { it in currentTopics }
.run {
logger.info("Creating $size topics")
kafkaAdmin.createTopics { this }
}
logger.info("Creating ${kafkatorioTopics.size} topics")
val result = kafkaAdmin.createTopics { kafkatorioTopics }
// wait for all brokers to become aware of the created topics
Thread.sleep(TimeUnit.SECONDS.toMillis(5))
@ -71,6 +69,7 @@ object CreateTopics {
}
}
}
}
private fun Admin.createTopics(
numPartitions: Int = 3,