-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4525 from navikt/feature/consumer-group
Feature/consumer group
- Loading branch information
Showing
11 changed files
with
116 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 3 additions & 23 deletions
26
common/kafka/src/main/kotlin/no/nav/mulighetsrommet/kafka/KafkaTopicConsumer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,19 @@ | ||
package no.nav.mulighetsrommet.kafka | ||
|
||
import kotlinx.coroutines.runBlocking | ||
import no.nav.common.kafka.consumer.util.KafkaConsumerClientBuilder.TopicConfig | ||
import no.nav.mulighetsrommet.metrics.Metrikker | ||
import org.apache.kafka.common.serialization.Deserializer | ||
import java.util.function.Consumer | ||
|
||
abstract class KafkaTopicConsumer<K, V>( | ||
val config: Config, | ||
private val keyDeserializer: Deserializer<K>, | ||
private val valueDeserializer: Deserializer<V>, | ||
val keyDeserializer: Deserializer<K>, | ||
val valueDeserializer: Deserializer<V>, | ||
) { | ||
|
||
data class Config( | ||
val id: String, | ||
val topic: String, | ||
val initialRunningState: Boolean = false, | ||
val consumerGroupId: String? = null, | ||
) | ||
|
||
internal fun toTopicConfig(kafkaConsumerRepository: KafkaConsumerRepositoryImpl): TopicConfig<K, V> { | ||
return TopicConfig<K, V>() | ||
.withMetrics(Metrikker.appMicrometerRegistry) | ||
.withLogging() | ||
.withStoreOnFailure(kafkaConsumerRepository) | ||
.withConsumerConfig( | ||
config.topic, | ||
keyDeserializer, | ||
valueDeserializer, | ||
Consumer { event -> | ||
runBlocking { | ||
consume(event.key(), event.value()) | ||
} | ||
}, | ||
) | ||
} | ||
|
||
abstract suspend fun consume(key: K, message: V) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters