Skip to content

Commit d805d6a

Browse files
authored
spring-kafka: improve kafka publisher listener selection strategy (#602)
1 parent a4efa1e commit d805d6a

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ projectUrl=https://github.com/Trendyol/stove
99
licenceUrl=https://github.com/Trendyol/stove/blob/master/LICENCE
1010
licence=Apache-2.0 license
1111
snapshot=1.0.0-SNAPSHOT
12-
version=0.14.0
12+
version=0.14.1
1313

1414

starters/spring/stove-spring-testing-e2e-kafka/src/main/kotlin/com/trendyol/stove/testing/e2e/kafka/KafkaSystem.kt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,27 @@ class KafkaSystem(
5353
it.setProducerListener(getInterceptor())
5454
it.setCloseTimeout(1.seconds.toJavaDuration())
5555
}
56-
.firstOrNone {
57-
it.producerFactory.configurationProperties[ProducerConfig.BOOTSTRAP_SERVERS_CONFIG] == exposedConfiguration.bootstrapServers
58-
}
56+
.firstOrNone { safeContains(it, exposedConfiguration) }
5957
.getOrElse {
6058
logger.warn("No KafkaTemplate found for the configured bootstrap servers, using a fallback KafkaTemplate")
6159
createFallbackTemplate(exposedConfiguration)
6260
}
6361
}
6462

63+
@Suppress("UNCHECKED_CAST")
64+
private fun safeContains(
65+
it: KafkaTemplate<Any, Any>,
66+
exposedConfiguration: KafkaExposedConfiguration
67+
): Boolean = it.producerFactory.configurationProperties[ProducerConfig.BOOTSTRAP_SERVERS_CONFIG]
68+
.toOption()
69+
.map {
70+
when (it) {
71+
is String -> it
72+
is List<*> -> (it as List<String>).joinToString(",")
73+
else -> ""
74+
}
75+
}.isSome { it.contains(exposedConfiguration.bootstrapServers) }
76+
6577
private fun createFallbackTemplate(exposedConfiguration: KafkaExposedConfiguration): KafkaTemplate<Any, Any> {
6678
val producerFactory = DefaultKafkaProducerFactory<Any, Any>(
6779
mapOf(

0 commit comments

Comments
 (0)