diff --git a/README.md b/README.md
index be6d6b5..ea0c02b 100644
--- a/README.md
+++ b/README.md
@@ -28,7 +28,10 @@ Wurde die Verwendung von gPAS konfiguriert, so sind weitere Angaben zu konfiguri
## Mögliche Endpunkte
-Für REST-Requests als auch (parallel) zur Nutzung von Kafka-Topics können Endpunkte konfiguriert werden.
+Für REST-Requests als auch zur Nutzung von Kafka-Topics können Endpunkte konfiguriert werden.
+
+Es ist dabei nur die Konfiguration eines Endpunkts zulässig.
+Werden sowohl REST als auch Kafka-Endpunkt konfiguriert, wird nur der REST-Endpunkt verwendet.
### REST
diff --git a/src/integrationTest/kotlin/dev/dnpm/etl/processor/config/AppConfigurationTest.kt b/src/integrationTest/kotlin/dev/dnpm/etl/processor/config/AppConfigurationTest.kt
new file mode 100644
index 0000000..8bdaa60
--- /dev/null
+++ b/src/integrationTest/kotlin/dev/dnpm/etl/processor/config/AppConfigurationTest.kt
@@ -0,0 +1,102 @@
+/*
+ * This file is part of ETL-Processor
+ *
+ * Copyright (c) 2023 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 .
+ */
+
+package dev.dnpm.etl.processor.config
+
+import com.fasterxml.jackson.databind.ObjectMapper
+import dev.dnpm.etl.processor.monitoring.RequestRepository
+import dev.dnpm.etl.processor.output.KafkaMtbFileSender
+import dev.dnpm.etl.processor.output.RestMtbFileSender
+import org.assertj.core.api.Assertions.assertThat
+import org.junit.jupiter.api.Nested
+import org.junit.jupiter.api.Test
+import org.junit.jupiter.api.assertThrows
+import org.springframework.beans.factory.NoSuchBeanDefinitionException
+import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration
+import org.springframework.boot.test.context.SpringBootTest
+import org.springframework.boot.test.mock.mockito.MockBean
+import org.springframework.boot.test.mock.mockito.MockBeans
+import org.springframework.context.ApplicationContext
+import org.springframework.test.context.ContextConfiguration
+import org.springframework.test.context.TestPropertySource
+
+@SpringBootTest
+@ContextConfiguration(classes = [KafkaAutoConfiguration::class, AppKafkaConfiguration::class, AppRestConfiguration::class])
+class AppConfigurationTest {
+
+ @Nested
+ @TestPropertySource(
+ properties = [
+ "app.rest.uri=http://localhost:9000"
+ ]
+ )
+ inner class AppConfigurationRestTest(private val context: ApplicationContext) {
+
+ @Test
+ fun shouldUseRestMtbFileSenderNotKafkaMtbFileSender() {
+ assertThat(context.getBean(RestMtbFileSender::class.java)).isNotNull
+ assertThrows { context.getBean(KafkaMtbFileSender::class.java) }
+ }
+
+ }
+
+ @Nested
+ @TestPropertySource(
+ properties = [
+ "app.kafka.servers=localhost:9092",
+ "app.kafka.topic=test",
+ "app.kafka.response-topic=test-response",
+ "app.kafka.group-id=test"
+ ]
+ )
+ @MockBeans(value = [
+ MockBean(ObjectMapper::class),
+ MockBean(RequestRepository::class)
+ ])
+ inner class AppConfigurationKafkaTest(private val context: ApplicationContext) {
+
+ @Test
+ fun shouldUseKafkaMtbFileSenderNotRestMtbFileSender() {
+ assertThrows { context.getBean(RestMtbFileSender::class.java) }
+ assertThat(context.getBean(KafkaMtbFileSender::class.java)).isNotNull
+ }
+
+ }
+
+ @Nested
+ @TestPropertySource(
+ properties = [
+ "app.rest.uri=http://localhost:9000",
+ "app.kafka.servers=localhost:9092",
+ "app.kafka.topic=test",
+ "app.kafka.response-topic=test-response",
+ "app.kafka.group-id=test"
+ ]
+ )
+ inner class AppConfigurationRestInPrecedenceTest(private val context: ApplicationContext) {
+
+ @Test
+ fun shouldUseRestMtbFileSenderNotKafkaMtbFileSender() {
+ assertThat(context.getBean(RestMtbFileSender::class.java)).isNotNull
+ assertThrows { context.getBean(KafkaMtbFileSender::class.java) }
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/kotlin/dev/dnpm/etl/processor/config/AppConfiguration.kt b/src/main/kotlin/dev/dnpm/etl/processor/config/AppConfiguration.kt
index cbba1f1..6b15fc0 100644
--- a/src/main/kotlin/dev/dnpm/etl/processor/config/AppConfiguration.kt
+++ b/src/main/kotlin/dev/dnpm/etl/processor/config/AppConfiguration.kt
@@ -21,8 +21,6 @@ package dev.dnpm.etl.processor.config
import com.fasterxml.jackson.databind.ObjectMapper
import dev.dnpm.etl.processor.monitoring.ReportService
-import dev.dnpm.etl.processor.output.MtbFileSender
-import dev.dnpm.etl.processor.output.RestMtbFileSender
import dev.dnpm.etl.processor.pseudonym.AnonymizingGenerator
import dev.dnpm.etl.processor.pseudonym.Generator
import dev.dnpm.etl.processor.pseudonym.GpasPseudonymGenerator
@@ -38,9 +36,7 @@ import reactor.core.publisher.Sinks
value = [
AppConfigProperties::class,
PseudonymizeConfigProperties::class,
- GPasConfigProperties::class,
- RestTargetProperties::class,
- KafkaTargetProperties::class
+ GPasConfigProperties::class
]
)
class AppConfiguration {
@@ -65,12 +61,6 @@ class AppConfiguration {
return PseudonymizeService(generator, pseudonymizeConfigProperties)
}
- @ConditionalOnProperty(value = ["app.rest.uri"])
- @Bean
- fun restMtbFileSender(restTargetProperties: RestTargetProperties): MtbFileSender {
- return RestMtbFileSender(restTargetProperties)
- }
-
@Bean
fun reportService(objectMapper: ObjectMapper): ReportService {
return ReportService(objectMapper)
diff --git a/src/main/kotlin/dev/dnpm/etl/processor/config/AppKafkaConfiguration.kt b/src/main/kotlin/dev/dnpm/etl/processor/config/AppKafkaConfiguration.kt
index 7adcb02..6d0254e 100644
--- a/src/main/kotlin/dev/dnpm/etl/processor/config/AppKafkaConfiguration.kt
+++ b/src/main/kotlin/dev/dnpm/etl/processor/config/AppKafkaConfiguration.kt
@@ -24,10 +24,13 @@ import dev.dnpm.etl.processor.monitoring.RequestRepository
import dev.dnpm.etl.processor.output.KafkaMtbFileSender
import dev.dnpm.etl.processor.output.MtbFileSender
import dev.dnpm.etl.processor.services.kafka.KafkaResponseProcessor
+import org.slf4j.LoggerFactory
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
+import org.springframework.core.annotation.Order
import org.springframework.kafka.core.ConsumerFactory
import org.springframework.kafka.core.KafkaTemplate
import org.springframework.kafka.listener.ContainerProperties
@@ -38,14 +41,19 @@ import org.springframework.kafka.listener.KafkaMessageListenerContainer
value = [KafkaTargetProperties::class]
)
@ConditionalOnProperty(value = ["app.kafka.topic", "app.kafka.servers"])
+@ConditionalOnMissingBean(MtbFileSender::class)
+@Order(-5)
class AppKafkaConfiguration {
+ private val logger = LoggerFactory.getLogger(AppKafkaConfiguration::class.java)
+
@Bean
fun kafkaMtbFileSender(
kafkaTemplate: KafkaTemplate,
kafkaTargetProperties: KafkaTargetProperties,
objectMapper: ObjectMapper
): MtbFileSender {
+ logger.info("Selected 'KafkaMtbFileSender'")
return KafkaMtbFileSender(kafkaTemplate, kafkaTargetProperties, objectMapper)
}
diff --git a/src/main/kotlin/dev/dnpm/etl/processor/config/AppRestConfiguration.kt b/src/main/kotlin/dev/dnpm/etl/processor/config/AppRestConfiguration.kt
new file mode 100644
index 0000000..5e77a4f
--- /dev/null
+++ b/src/main/kotlin/dev/dnpm/etl/processor/config/AppRestConfiguration.kt
@@ -0,0 +1,52 @@
+/*
+ * This file is part of ETL-Processor
+ *
+ * Copyright (c) 2023 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 .
+ */
+
+package dev.dnpm.etl.processor.config
+
+import dev.dnpm.etl.processor.output.MtbFileSender
+import dev.dnpm.etl.processor.output.RestMtbFileSender
+import org.slf4j.LoggerFactory
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
+import org.springframework.boot.context.properties.EnableConfigurationProperties
+import org.springframework.context.annotation.Bean
+import org.springframework.context.annotation.Configuration
+import org.springframework.core.annotation.Order
+
+@Configuration
+@EnableConfigurationProperties(
+ value = [
+ RestTargetProperties::class
+ ]
+)
+@ConditionalOnProperty(value = ["app.rest.uri"])
+@ConditionalOnMissingBean(MtbFileSender::class)
+@Order(-10)
+class AppRestConfiguration {
+
+ private val logger = LoggerFactory.getLogger(AppRestConfiguration::class.java)
+
+ @Bean
+ fun restMtbFileSender(restTargetProperties: RestTargetProperties): MtbFileSender {
+ logger.info("Selected 'RestMtbFileSender'")
+ return RestMtbFileSender(restTargetProperties)
+ }
+
+}
+