mirror of
https://github.com/pcvolkmer/etl-processor.git
synced 2025-04-19 17:26:51 +00:00
feat: new kafka config due to kafka input
This commit is contained in:
parent
f5c80f6d81
commit
50a6d66718
@ -20,6 +20,7 @@
|
|||||||
package dev.dnpm.etl.processor.config
|
package dev.dnpm.etl.processor.config
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
|
import dev.dnpm.etl.processor.input.KafkaInputListener
|
||||||
import dev.dnpm.etl.processor.monitoring.RequestRepository
|
import dev.dnpm.etl.processor.monitoring.RequestRepository
|
||||||
import dev.dnpm.etl.processor.output.KafkaMtbFileSender
|
import dev.dnpm.etl.processor.output.KafkaMtbFileSender
|
||||||
import dev.dnpm.etl.processor.output.RestMtbFileSender
|
import dev.dnpm.etl.processor.output.RestMtbFileSender
|
||||||
@ -78,8 +79,8 @@ class AppConfigurationTest {
|
|||||||
@TestPropertySource(
|
@TestPropertySource(
|
||||||
properties = [
|
properties = [
|
||||||
"app.kafka.servers=localhost:9092",
|
"app.kafka.servers=localhost:9092",
|
||||||
"app.kafka.topic=test",
|
"app.kafka.output-topic=test",
|
||||||
"app.kafka.response-topic=test-response",
|
"app.kafka.output-response-topic=test-response",
|
||||||
"app.kafka.group-id=test"
|
"app.kafka.group-id=test"
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@ -99,8 +100,8 @@ class AppConfigurationTest {
|
|||||||
properties = [
|
properties = [
|
||||||
"app.rest.uri=http://localhost:9000",
|
"app.rest.uri=http://localhost:9000",
|
||||||
"app.kafka.servers=localhost:9092",
|
"app.kafka.servers=localhost:9092",
|
||||||
"app.kafka.topic=test",
|
"app.kafka.output-topic=test",
|
||||||
"app.kafka.response-topic=test-response",
|
"app.kafka.output-response-topic=test-response",
|
||||||
"app.kafka.group-id=test"
|
"app.kafka.group-id=test"
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@ -114,6 +115,43 @@ class AppConfigurationTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
@TestPropertySource(
|
||||||
|
properties = [
|
||||||
|
"app.kafka.servers=localhost:9092",
|
||||||
|
"app.kafka.output-topic=test",
|
||||||
|
"app.kafka.output-response-topic=test-response",
|
||||||
|
"app.kafka.group-id=test"
|
||||||
|
]
|
||||||
|
)
|
||||||
|
inner class AppConfigurationWithoutKafkaInputTest(private val context: ApplicationContext) {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun shouldNotUseKafkaInputListener() {
|
||||||
|
assertThrows<NoSuchBeanDefinitionException> { context.getBean(KafkaInputListener::class.java) }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
@TestPropertySource(
|
||||||
|
properties = [
|
||||||
|
"app.kafka.servers=localhost:9092",
|
||||||
|
"app.kafka.input-topic=test_input",
|
||||||
|
"app.kafka.output-topic=test",
|
||||||
|
"app.kafka.output-response-topic=test-response",
|
||||||
|
"app.kafka.group-id=test"
|
||||||
|
]
|
||||||
|
)
|
||||||
|
inner class AppConfigurationUsingKafkaInputTest(private val context: ApplicationContext) {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun shouldUseKafkaInputListener() {
|
||||||
|
assertThat(context.getBean(KafkaInputListener::class.java)).isNotNull
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@TestPropertySource(
|
@TestPropertySource(
|
||||||
properties = [
|
properties = [
|
||||||
|
@ -72,10 +72,21 @@ data class RestTargetProperties(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConfigurationProperties(KafkaTargetProperties.NAME)
|
@ConfigurationProperties(KafkaProperties.NAME)
|
||||||
data class KafkaTargetProperties(
|
data class KafkaProperties(
|
||||||
val topic: String = "etl-processor",
|
val inputTopic: String?,
|
||||||
val responseTopic: String = "${topic}_response",
|
val outputTopic: String = "etl-processor",
|
||||||
|
@get:DeprecatedConfigurationProperty(
|
||||||
|
reason = "Deprecated",
|
||||||
|
replacement = "outputTopic"
|
||||||
|
)
|
||||||
|
val topic: String = outputTopic,
|
||||||
|
val outputResponseTopic: String = "${outputTopic}_response",
|
||||||
|
@get:DeprecatedConfigurationProperty(
|
||||||
|
reason = "Deprecated",
|
||||||
|
replacement = "outputResponseTopic"
|
||||||
|
)
|
||||||
|
val responseTopic: String = outputResponseTopic,
|
||||||
val groupId: String = "${topic}_group",
|
val groupId: String = "${topic}_group",
|
||||||
val servers: String = ""
|
val servers: String = ""
|
||||||
) {
|
) {
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package dev.dnpm.etl.processor.config
|
package dev.dnpm.etl.processor.config
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
|
import dev.dnpm.etl.processor.input.KafkaInputListener
|
||||||
import dev.dnpm.etl.processor.monitoring.ConnectionCheckService
|
import dev.dnpm.etl.processor.monitoring.ConnectionCheckService
|
||||||
import dev.dnpm.etl.processor.monitoring.KafkaConnectionCheckService
|
import dev.dnpm.etl.processor.monitoring.KafkaConnectionCheckService
|
||||||
import dev.dnpm.etl.processor.output.KafkaMtbFileSender
|
import dev.dnpm.etl.processor.output.KafkaMtbFileSender
|
||||||
@ -42,9 +43,9 @@ import reactor.core.publisher.Sinks
|
|||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableConfigurationProperties(
|
@EnableConfigurationProperties(
|
||||||
value = [KafkaTargetProperties::class]
|
value = [KafkaProperties::class]
|
||||||
)
|
)
|
||||||
@ConditionalOnProperty(value = ["app.kafka.topic", "app.kafka.servers"])
|
@ConditionalOnProperty(value = ["app.kafka.servers"])
|
||||||
@ConditionalOnMissingBean(MtbFileSender::class)
|
@ConditionalOnMissingBean(MtbFileSender::class)
|
||||||
@Order(-5)
|
@Order(-5)
|
||||||
class AppKafkaConfiguration {
|
class AppKafkaConfiguration {
|
||||||
@ -54,21 +55,21 @@ class AppKafkaConfiguration {
|
|||||||
@Bean
|
@Bean
|
||||||
fun kafkaMtbFileSender(
|
fun kafkaMtbFileSender(
|
||||||
kafkaTemplate: KafkaTemplate<String, String>,
|
kafkaTemplate: KafkaTemplate<String, String>,
|
||||||
kafkaTargetProperties: KafkaTargetProperties,
|
kafkaProperties: KafkaProperties,
|
||||||
retryTemplate: RetryTemplate,
|
retryTemplate: RetryTemplate,
|
||||||
objectMapper: ObjectMapper
|
objectMapper: ObjectMapper
|
||||||
): MtbFileSender {
|
): MtbFileSender {
|
||||||
logger.info("Selected 'KafkaMtbFileSender'")
|
logger.info("Selected 'KafkaMtbFileSender'")
|
||||||
return KafkaMtbFileSender(kafkaTemplate, kafkaTargetProperties, retryTemplate, objectMapper)
|
return KafkaMtbFileSender(kafkaTemplate, kafkaProperties, retryTemplate, objectMapper)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
fun kafkaListenerContainer(
|
fun kafkaResponseListenerContainer(
|
||||||
consumerFactory: ConsumerFactory<String, String>,
|
consumerFactory: ConsumerFactory<String, String>,
|
||||||
kafkaTargetProperties: KafkaTargetProperties,
|
kafkaProperties: KafkaProperties,
|
||||||
kafkaResponseProcessor: KafkaResponseProcessor
|
kafkaResponseProcessor: KafkaResponseProcessor
|
||||||
): KafkaMessageListenerContainer<String, String> {
|
): KafkaMessageListenerContainer<String, String> {
|
||||||
val containerProperties = ContainerProperties(kafkaTargetProperties.responseTopic)
|
val containerProperties = ContainerProperties(kafkaProperties.responseTopic)
|
||||||
containerProperties.messageListener = kafkaResponseProcessor
|
containerProperties.messageListener = kafkaResponseProcessor
|
||||||
return KafkaMessageListenerContainer(consumerFactory, containerProperties)
|
return KafkaMessageListenerContainer(consumerFactory, containerProperties)
|
||||||
}
|
}
|
||||||
@ -81,6 +82,26 @@ class AppKafkaConfiguration {
|
|||||||
return KafkaResponseProcessor(applicationEventPublisher, objectMapper)
|
return KafkaResponseProcessor(applicationEventPublisher, objectMapper)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnProperty(value = ["app.kafka.input-topic"])
|
||||||
|
fun kafkaInputListenerContainer(
|
||||||
|
consumerFactory: ConsumerFactory<String, String>,
|
||||||
|
kafkaProperties: KafkaProperties,
|
||||||
|
kafkaInputListener: KafkaInputListener
|
||||||
|
): KafkaMessageListenerContainer<String, String> {
|
||||||
|
val containerProperties = ContainerProperties(kafkaProperties.inputTopic)
|
||||||
|
containerProperties.messageListener = kafkaInputListener
|
||||||
|
return KafkaMessageListenerContainer(consumerFactory, containerProperties)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnProperty(value = ["app.kafka.input-topic"])
|
||||||
|
fun kafkaInputListener(
|
||||||
|
applicationEventPublisher: ApplicationEventPublisher,
|
||||||
|
): KafkaInputListener {
|
||||||
|
return KafkaInputListener(applicationEventPublisher)
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
fun connectionCheckService(consumerFactory: ConsumerFactory<String, String>, configsUpdateProducer: Sinks.Many<Boolean>): ConnectionCheckService {
|
fun connectionCheckService(consumerFactory: ConsumerFactory<String, String>, configsUpdateProducer: Sinks.Many<Boolean>): ConnectionCheckService {
|
||||||
return KafkaConnectionCheckService(consumerFactory.createConsumer(), configsUpdateProducer)
|
return KafkaConnectionCheckService(consumerFactory.createConsumer(), configsUpdateProducer)
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ETL-Processor
|
||||||
|
*
|
||||||
|
* Copyright (c) 2024 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
|
* by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package dev.dnpm.etl.processor.input
|
||||||
|
|
||||||
|
import de.ukw.ccc.bwhc.dto.MtbFile
|
||||||
|
import org.apache.kafka.clients.consumer.ConsumerRecord
|
||||||
|
import org.springframework.context.ApplicationEventPublisher
|
||||||
|
import org.springframework.kafka.listener.MessageListener
|
||||||
|
|
||||||
|
class KafkaInputListener(
|
||||||
|
private val applicationEventPublisher: ApplicationEventPublisher
|
||||||
|
) : MessageListener<String, MtbFile> {
|
||||||
|
override fun onMessage(data: ConsumerRecord<String, MtbFile>) {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
}
|
@ -22,7 +22,7 @@ package dev.dnpm.etl.processor.output
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
import de.ukw.ccc.bwhc.dto.Consent
|
import de.ukw.ccc.bwhc.dto.Consent
|
||||||
import de.ukw.ccc.bwhc.dto.MtbFile
|
import de.ukw.ccc.bwhc.dto.MtbFile
|
||||||
import dev.dnpm.etl.processor.config.KafkaTargetProperties
|
import dev.dnpm.etl.processor.config.KafkaProperties
|
||||||
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.kafka.core.KafkaTemplate
|
import org.springframework.kafka.core.KafkaTemplate
|
||||||
@ -30,7 +30,7 @@ import org.springframework.retry.support.RetryTemplate
|
|||||||
|
|
||||||
class KafkaMtbFileSender(
|
class KafkaMtbFileSender(
|
||||||
private val kafkaTemplate: KafkaTemplate<String, String>,
|
private val kafkaTemplate: KafkaTemplate<String, String>,
|
||||||
private val kafkaTargetProperties: KafkaTargetProperties,
|
private val kafkaProperties: KafkaProperties,
|
||||||
private val retryTemplate: RetryTemplate,
|
private val retryTemplate: RetryTemplate,
|
||||||
private val objectMapper: ObjectMapper
|
private val objectMapper: ObjectMapper
|
||||||
) : MtbFileSender {
|
) : MtbFileSender {
|
||||||
@ -41,7 +41,7 @@ class KafkaMtbFileSender(
|
|||||||
return try {
|
return try {
|
||||||
return retryTemplate.execute<MtbFileSender.Response, Exception> {
|
return retryTemplate.execute<MtbFileSender.Response, Exception> {
|
||||||
val result = kafkaTemplate.send(
|
val result = kafkaTemplate.send(
|
||||||
kafkaTargetProperties.topic,
|
kafkaProperties.topic,
|
||||||
key(request),
|
key(request),
|
||||||
objectMapper.writeValueAsString(Data(request.requestId, request.mtbFile))
|
objectMapper.writeValueAsString(Data(request.requestId, request.mtbFile))
|
||||||
)
|
)
|
||||||
@ -71,7 +71,7 @@ class KafkaMtbFileSender(
|
|||||||
return try {
|
return try {
|
||||||
return retryTemplate.execute<MtbFileSender.Response, Exception> {
|
return retryTemplate.execute<MtbFileSender.Response, Exception> {
|
||||||
val result = kafkaTemplate.send(
|
val result = kafkaTemplate.send(
|
||||||
kafkaTargetProperties.topic,
|
kafkaProperties.topic,
|
||||||
key(request),
|
key(request),
|
||||||
objectMapper.writeValueAsString(Data(request.requestId, dummyMtbFile))
|
objectMapper.writeValueAsString(Data(request.requestId, dummyMtbFile))
|
||||||
)
|
)
|
||||||
@ -90,7 +90,7 @@ class KafkaMtbFileSender(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun endpoint(): String {
|
override fun endpoint(): String {
|
||||||
return "${this.kafkaTargetProperties.servers} (${this.kafkaTargetProperties.topic}/${this.kafkaTargetProperties.responseTopic})"
|
return "${this.kafkaProperties.servers} (${this.kafkaProperties.topic}/${this.kafkaProperties.responseTopic})"
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun key(request: MtbFileSender.MtbFileRequest): String {
|
private fun key(request: MtbFileSender.MtbFileRequest): String {
|
||||||
|
@ -21,7 +21,7 @@ package dev.dnpm.etl.processor.output
|
|||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
import de.ukw.ccc.bwhc.dto.*
|
import de.ukw.ccc.bwhc.dto.*
|
||||||
import dev.dnpm.etl.processor.config.KafkaTargetProperties
|
import dev.dnpm.etl.processor.config.KafkaProperties
|
||||||
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
@ -53,13 +53,13 @@ class KafkaMtbFileSenderTest {
|
|||||||
fun setup(
|
fun setup(
|
||||||
@Mock kafkaTemplate: KafkaTemplate<String, String>
|
@Mock kafkaTemplate: KafkaTemplate<String, String>
|
||||||
) {
|
) {
|
||||||
val kafkaTargetProperties = KafkaTargetProperties("testtopic")
|
val kafkaProperties = KafkaProperties("testtopic")
|
||||||
val retryTemplate = RetryTemplateBuilder().customPolicy(SimpleRetryPolicy(1)).build()
|
val retryTemplate = RetryTemplateBuilder().customPolicy(SimpleRetryPolicy(1)).build()
|
||||||
|
|
||||||
this.objectMapper = ObjectMapper()
|
this.objectMapper = ObjectMapper()
|
||||||
this.kafkaTemplate = kafkaTemplate
|
this.kafkaTemplate = kafkaTemplate
|
||||||
|
|
||||||
this.kafkaMtbFileSender = KafkaMtbFileSender(kafkaTemplate, kafkaTargetProperties, retryTemplate, objectMapper)
|
this.kafkaMtbFileSender = KafkaMtbFileSender(kafkaTemplate, kafkaProperties, retryTemplate, objectMapper)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@ -125,9 +125,9 @@ class KafkaMtbFileSenderTest {
|
|||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("requestWithResponseSource")
|
@MethodSource("requestWithResponseSource")
|
||||||
fun shouldRetryOnMtbFileKafkaSendError(testData: TestData) {
|
fun shouldRetryOnMtbFileKafkaSendError(testData: TestData) {
|
||||||
val kafkaTargetProperties = KafkaTargetProperties("testtopic")
|
val kafkaProperties = KafkaProperties("testtopic")
|
||||||
val retryTemplate = RetryTemplateBuilder().customPolicy(SimpleRetryPolicy(3)).build()
|
val retryTemplate = RetryTemplateBuilder().customPolicy(SimpleRetryPolicy(3)).build()
|
||||||
this.kafkaMtbFileSender = KafkaMtbFileSender(this.kafkaTemplate, kafkaTargetProperties, retryTemplate, this.objectMapper)
|
this.kafkaMtbFileSender = KafkaMtbFileSender(this.kafkaTemplate, kafkaProperties, retryTemplate, this.objectMapper)
|
||||||
|
|
||||||
doAnswer {
|
doAnswer {
|
||||||
if (null != testData.exception) {
|
if (null != testData.exception) {
|
||||||
@ -151,9 +151,9 @@ class KafkaMtbFileSenderTest {
|
|||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("requestWithResponseSource")
|
@MethodSource("requestWithResponseSource")
|
||||||
fun shouldRetryOnDeleteKafkaSendError(testData: TestData) {
|
fun shouldRetryOnDeleteKafkaSendError(testData: TestData) {
|
||||||
val kafkaTargetProperties = KafkaTargetProperties("testtopic")
|
val kafkaProperties = KafkaProperties("testtopic")
|
||||||
val retryTemplate = RetryTemplateBuilder().customPolicy(SimpleRetryPolicy(3)).build()
|
val retryTemplate = RetryTemplateBuilder().customPolicy(SimpleRetryPolicy(3)).build()
|
||||||
this.kafkaMtbFileSender = KafkaMtbFileSender(this.kafkaTemplate, kafkaTargetProperties, retryTemplate, this.objectMapper)
|
this.kafkaMtbFileSender = KafkaMtbFileSender(this.kafkaTemplate, kafkaProperties, retryTemplate, this.objectMapper)
|
||||||
|
|
||||||
doAnswer {
|
doAnswer {
|
||||||
if (null != testData.exception) {
|
if (null != testData.exception) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user