only try to create topics if there are topics to be created
This commit is contained in:
parent
dbeb0e73dd
commit
4fc55b706f
1 changed files with 20 additions and 21 deletions
|
|
@ -30,6 +30,8 @@ object CreateTopics {
|
||||||
|
|
||||||
KafkatorioPacket.PacketType.values().forEach { packetType ->
|
KafkatorioPacket.PacketType.values().forEach { packetType ->
|
||||||
|
|
||||||
|
val currentTopics = currentTopics().map { it.name() }
|
||||||
|
|
||||||
val kafkatorioTopics = buildSet {
|
val kafkatorioTopics = buildSet {
|
||||||
add(KafkatorioTopology.sourceTopic)
|
add(KafkatorioTopology.sourceTopic)
|
||||||
when (packetType) {
|
when (packetType) {
|
||||||
|
|
@ -42,16 +44,12 @@ object CreateTopics {
|
||||||
KafkatorioPacket.PacketType.PROTOTYPES ->
|
KafkatorioPacket.PacketType.PROTOTYPES ->
|
||||||
add("kafkatorio.${packetType.name}.all")
|
add("kafkatorio.${packetType.name}.all")
|
||||||
}
|
}
|
||||||
}
|
}.minus(currentTopics.toSet())
|
||||||
|
|
||||||
val currentTopics = currentTopics().map { it.name() }
|
if (currentTopics.isNotEmpty()) {
|
||||||
|
|
||||||
val result = kafkatorioTopics
|
logger.info("Creating ${kafkatorioTopics.size} topics")
|
||||||
.filterNot { it in currentTopics }
|
val result = kafkaAdmin.createTopics { kafkatorioTopics }
|
||||||
.run {
|
|
||||||
logger.info("Creating $size topics")
|
|
||||||
kafkaAdmin.createTopics { this }
|
|
||||||
}
|
|
||||||
|
|
||||||
// wait for all brokers to become aware of the created topics
|
// wait for all brokers to become aware of the created topics
|
||||||
Thread.sleep(TimeUnit.SECONDS.toMillis(5))
|
Thread.sleep(TimeUnit.SECONDS.toMillis(5))
|
||||||
|
|
@ -71,6 +69,7 @@ object CreateTopics {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun Admin.createTopics(
|
private fun Admin.createTopics(
|
||||||
numPartitions: Int = 3,
|
numPartitions: Int = 3,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue