https://github.com/adamko-dev/kotka-streams
Kotka Streams - the Kotlin DSL for Kafka Streams
https://github.com/adamko-dev/kotka-streams
kafka kafka-streams kotlin kotlin-dsl
Last synced: 2 months ago
JSON representation
Kotka Streams - the Kotlin DSL for Kafka Streams
- Host: GitHub
- URL: https://github.com/adamko-dev/kotka-streams
- Owner: adamko-dev
- License: apache-2.0
- Created: 2022-01-15T12:36:32.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-04-23T12:29:48.000Z (2 months ago)
- Last Synced: 2025-04-23T13:49:55.941Z (2 months ago)
- Topics: kafka, kafka-streams, kotlin, kotlin-dsl
- Language: Kotlin
- Homepage: https://adamko-dev.github.io/kotka-streams/
- Size: 1010 KB
- Stars: 16
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/adamko-dev/kotka-streams/blob/main/LICENSE)
[](https://jitpack.io/#adamko-dev/kotka-streams)
[](https://search.maven.org/search?q=g:dev.adamko.kotka)
[](https://s01.oss.sonatype.org/content/repositories/snapshots/dev/adamko/kotka/)# Kotka Streams - Kotlin for Kafka Streams
Using [Kotka](https://github.com/adamko-dev/kotka-streams) means a more pleasant experience while
using [Kafka Streams](https://kafka.apache.org/documentation/streams/).## Quickstart
Add a dependency on `kotka-streams-extensions` for the basics.
```kotlin
// build.gradle.kts
repositories {
mavenCentral()
}dependencies {
implementation("dev.adamko.kotka:kotka-streams-extensions:$kotkaVersion")
}
```## Modules
There are three modules. Add a dependency on `com.github.adamko-dev:kotka-streams` to get them all
at once```kotlin
dependencies {
implementation("dev.adamko.kotka:kotka-streams:$kotkaVersion")
}
```### `kotka-streams-extensions`
Contains the basic extension functions to make Kafka Streams more Kotlin-esque.
```kotlin
implementation("dev.adamko.kotka:kotka-streams-extensions:$kotkaVersion")
``````kotlin
import dev.adamko.kotka.extensions.tables.*
import dev.adamko.kotka.extensions.streams.*
import dev.adamko.kotka.extensions.*data class MusicalBand(
val name: String,
val memberNames: List,
)builder.stream("musical-bands")
.flatMap("band-member-names-to-band-name") { _: String, band: MusicalBand ->
band.memberNames.map { memberName -> memberName to band.name }
}
.groupByKey(groupedAs("map-of-band-member-to-band-names"))
```### `kotka-streams-framework`
A light framework for structuring topics and records.
```kotlin
implementation("dev.adamko.kotka:kotka-streams-framework:$kotkaVersion")
```Use `TopicRecord` to standardise the data on each topic. Records can now easily be converted from
one type, to another.```kotlin
import dev.adamko.kotka.extensions.tables.*
import dev.adamko.kotka.extensions.streams.*
import dev.adamko.kotka.extensions.*
import dev.adamko.kotka.topicdata.*data class Animal(
val id: Long,
val name: String,
) : TopicRecord {
override val topicKey: Long by ::id
}data class Pet(
val id: Long,
val name: String,
) : TopicRecord {
override val topicKey: Long by ::id
}val petUpdates = builder.stream("animals")
.mapTopicRecords("convert-animals-to-pets") { _, animal ->
Pet(animal.id, animal.name)
}
```Use `KeyValueSerdes` to define both the key and value serdes for a topic.
A `TopicDefinition` ties both of these together.```kotlin
/** All [Pet] updates */
object PetUpdatesTopic : TopicDefinition {
override val topicName = "pet-updates"
override val serdes = KeyValueSerdes(Serdes.Long(), PetSerde())
}petUpdates
.to(
PetUpdatesTopic.topicName,
PetUpdatesTopic.serdes.producer("send-pet-updates-to-pet-update-topic")
)
```### `kotka-streams-kotlinx-serialization`
Use [Kotlinx Serialization](https://github.com/Kotlin/kotlinx.serialization/) for topic key/value
serdes.```kotlin
implementation("dev.adamko.kotka:kotka-streams-kotlinx-serialization:$kotkaVersion")
``````kotlin
import dev.adamko.kotka.extensions.tables.*
import dev.adamko.kotka.extensions.streams.*
import dev.adamko.kotka.extensions.*
import dev.adamko.kotka.topicdata.*
import dev.adamko.kotka.kxs.*val jsonMapper = Json {}
@Serializable
data class Sku(
val sku: String
)@Serializable
data class ShopItem(
val id: Sku,
val name: String,
) : TopicRecord {
override val topicKey: Sku by ::id
}object ShopItemTopic : TopicDefinition {
override val topicName = "shop-item-updates"
override val serdes = KeyValueSerdes.kxsJson(jsonMapper)
}
```