Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/joan38/kafka-streams-circe

Generic Serdes with Circe for Kafka Streams
https://github.com/joan38/kafka-streams-circe

Last synced: about 2 months ago
JSON representation

Generic Serdes with Circe for Kafka Streams

Awesome Lists containing this project

README

        

# Kafka Streams Circe

[![Latest version](https://index.scala-lang.org/joan38/kafka-streams-circe/kafka-streams-circe/latest.svg)](https://index.scala-lang.org/joan38/kafka-streams-circe/kafka-streams-circe)

Generic Serdes with [Circe](https://github.com/circe/circe) for [Kafka Streams](https://github.com/apache/kafka)

## Installation
[Mill](https://www.lihaoyi.com/mill):
```scala
ivy"com.goyeau::kafka-streams-circe:"
```
or

[SBT](https://www.scala-sbt.org):
```scala
"com.goyeau" %% "kafka-streams-circe" % ""
```

## Example

```scala
import org.apache.kafka.streams.scala.StreamsBuilder
import org.apache.kafka.streams.scala.ImplicitConversions._
import org.apache.kafka.streams.scala.Serdes._
import com.goyeau.kafka.streams.circe.CirceSerdes._
import io.circe.generic.auto._

case class Person(firstname: String, lastname: String, age: Int)

object Streams extends App {
println("Starting streams")

val streamsBuilder = new StreamsBuilder
val testStream = streamsBuilder.stream[String, Person]("some-topic")
}
```

If you need to customize the json serialization, a custom implicit instance of `Printer` can be provided in scope.

For example, in the code below a custom printer is used to omit null values:
```scala
import org.apache.kafka.streams.scala.StreamsBuilder
import org.apache.kafka.streams.scala.ImplicitConversions._
import org.apache.kafka.streams.scala.Serdes._
import com.goyeau.kafka.streams.circe.CirceSerdes._
import io.circe.generic.auto._

case class Person(firstname: String, lastname: String, age: Int)

object Streams extends App {
implicit val printer = Printer.noSpaces.copy(dropNullValues = true)

val streamsBuilder = new StreamsBuilder
val testStream = streamsBuilder.stream[String, Person]("some-topic")
}
```