Skip to content
Snippets Groups Projects
Commit a0f00c91 authored by Lorenz Boguhn's avatar Lorenz Boguhn
Browse files

Rewrite TopicManager.kt

Enhance log by reusing same kafkaAdmin client
parent bf9cd122
No related branches found
No related tags found
4 merge requests!159Re-implementation of Theodolite with Kotlin/Quarkus,!157Update Graal Image in CI pipeline,!128Hotfix TopicManager again,!83WIP: Re-implementation of Theodolite with Kotlin/Quarkus
...@@ -30,7 +30,7 @@ class TopicManager(private val kafkaConfig: HashMap<String, Any>) { ...@@ -30,7 +30,7 @@ class TopicManager(private val kafkaConfig: HashMap<String, Any>) {
result.all().get()// wait for the future object result.all().get()// wait for the future object
} catch (e: Exception) { } catch (e: Exception) {
removeTopics(newTopics.map { topic -> topic.name() }) delete(newTopics.map { topic -> topic.name() }, kafkaAdmin)
logger.warn { "Error during topic creation." } logger.warn { "Error during topic creation." }
logger.debug { e } logger.debug { e }
logger.warn { "Will retry the topic creation after 2 seconds" } logger.warn { "Will retry the topic creation after 2 seconds" }
...@@ -54,6 +54,11 @@ class TopicManager(private val kafkaConfig: HashMap<String, Any>) { ...@@ -54,6 +54,11 @@ class TopicManager(private val kafkaConfig: HashMap<String, Any>) {
*/ */
fun removeTopics(topics: List<String>) { fun removeTopics(topics: List<String>) {
val kafkaAdmin: AdminClient = AdminClient.create(this.kafkaConfig) val kafkaAdmin: AdminClient = AdminClient.create(this.kafkaConfig)
delete(topics, kafkaAdmin)
kafkaAdmin.close()
}
private fun delete(topics: List<String>, kafkaAdmin: AdminClient) {
var deleted = false var deleted = false
while (!deleted) { while (!deleted) {
...@@ -82,6 +87,6 @@ class TopicManager(private val kafkaConfig: HashMap<String, Any>) { ...@@ -82,6 +87,6 @@ class TopicManager(private val kafkaConfig: HashMap<String, Any>) {
sleep(RETRY_TIME) sleep(RETRY_TIME)
} }
} }
kafkaAdmin.close()
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment