Skip to content

Commit

Permalink
La til liten util funksjon i kafka-key test for å beregne partisjonsn…
Browse files Browse the repository at this point in the history
…ummer basert på record key
  • Loading branch information
nilsmsa committed Oct 28, 2024
1 parent 35548ae commit 3fd5678
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/kafka-key-generator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ dependencies {
testImplementation(libs.test.testContainers.postgresql)
testImplementation(libs.ktor.server.testJvm)
testImplementation(libs.ktor.client.mock)
testImplementation(libs.kafka.clients)
}

java {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package no.nav.paw.kafkakeygenerator

import org.apache.kafka.clients.producer.internals.BuiltInPartitioner
import org.apache.kafka.common.serialization.Serdes

const val NUMBER_OF_PARTITIONS = 6

fun main() {
val recordKey: Long = 123
val partition = BuiltInPartitioner.partitionForKey(Serdes.Long().serializer().serialize("topic", recordKey), NUMBER_OF_PARTITIONS)
println("Record key $recordKey is assigned to partition $partition")
}

0 comments on commit 3fd5678

Please sign in to comment.