diff --git a/kafka/build.gradle.kts b/kafka/build.gradle.kts index c3280c6..b82bbce 100644 --- a/kafka/build.gradle.kts +++ b/kafka/build.gradle.kts @@ -1,3 +1,4 @@ dependencies { implementation("org.apache.kafka:kafka-clients:3.5.1") + testImplementation(kotlin("test")) } diff --git a/kafka/main/no/nav/aap/kafka/KafkaFactory.kt b/kafka/main/no/nav/aap/kafka/KafkaFactory.kt index 65a2bad..f09c6aa 100644 --- a/kafka/main/no/nav/aap/kafka/KafkaFactory.kt +++ b/kafka/main/no/nav/aap/kafka/KafkaFactory.kt @@ -2,12 +2,14 @@ package no.nav.aap.kafka import org.apache.kafka.clients.CommonClientConfigs import org.apache.kafka.clients.producer.KafkaProducer +import org.apache.kafka.clients.producer.Producer import org.apache.kafka.clients.producer.ProducerConfig import org.apache.kafka.common.config.SslConfigs -import org.apache.kafka.common.serialization.Serdes +import org.apache.kafka.common.serialization.Serdes.StringSerde +import org.apache.kafka.common.serialization.Serializer import java.util.* -class KafkaConfig( +data class KafkaConfig( val brokers: String, val truststorePath: String, val keystorePath: String, @@ -16,7 +18,11 @@ class KafkaConfig( class KafkaFactory private constructor() { companion object { - fun createProducer(clientId: String, config: KafkaConfig): KafkaProducer { + fun createProducer( + clientId: String, + config: KafkaConfig, + serializer: Serializer, + ): Producer { fun properties(): Properties = Properties().apply { this[CommonClientConfigs.CLIENT_ID_CONFIG] = clientId this[CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG] = config.brokers @@ -33,7 +39,10 @@ class KafkaFactory private constructor() { this[SslConfigs.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG] = "" } - return KafkaProducer(properties(), Serdes.StringSerde().serializer(), Serdes.StringSerde().serializer()) + return KafkaProducer(properties(), StringSerde().serializer(), serializer) } + + fun createProducer(clientId: String, config: KafkaConfig): Producer = + createProducer(clientId, config, StringSerde().serializer()) } } diff --git a/kafka/test/no/nav/aap/kafka/KafkaFactoryTest.kt b/kafka/test/no/nav/aap/kafka/KafkaFactoryTest.kt new file mode 100644 index 0000000..78c8130 --- /dev/null +++ b/kafka/test/no/nav/aap/kafka/KafkaFactoryTest.kt @@ -0,0 +1,11 @@ +package no.nav.aap.kafka + +import org.junit.jupiter.api.Test + +class KafkaFactoryTest { + + @Test + fun config() { + + } +} \ No newline at end of file