Scala API for Kafka Streams

Scala API for Kafka Streams is a separate Kafka Streams module (a Scala library) that acts as a wrapper over the existing Java API for Kafka Streams.

The Scala API is available in org.apache.kafka.streams.scala package.

As a separate Scala library you have to define the dependency in build.sbt.

// Note two percent signs (%%) to encode Scala version
libraryDependencies += "org.apache.kafka" %% "kafka-streams-scala" % "2.3.0"

The Scala API for Kafka Streams defines Scala-friendly types that wrap the corresponding Kafka Streams types and simply delegate all method calls to the underlying Java object with the purpose of making it much more expressive, with less boilerplate and more succinct.

Beside the Scala-friendly types, the Scala API for Kafka Streams defines implicit conversions, i.e. Serdes, and ImplicitConversions.

import org.apache.kafka.streams.scala._
import ImplicitConversions._
import Serdes._

The Scala API for Kafka Streams comes with Consumed Scala object that allows for creating Consumed instances with key and value Serdes objects available in implicit scope.

You could also use Serdes when defining StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG and StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG.

import org.apache.kafka.streams.scala.Serdes._
Scala API for Kafka Streams was added in Kafka Streams 2.0.0 as KAFKA-6670 Implement a Scala wrapper library for Kafka Streams.

results matching ""

    No results matching ""