Using Vulcan codecs with Kafka Java APIs

Click for: original source

For those that aren’t familiar, Vulcan is a functional Avro encoding library that uses the official Apache Avro library under the hood. The difference between this and the official Avro build plugins approach is that the types are defined in plain Scala. Then the Avro schema is generated from those instead of defining the Avro schema and getting code generated at compile time that adheres to that schema. By César Enrique.

import vulcan.Codec
import vulcan.generic.*
import java.time.Instant
import java.util.UUID

case class Data(id: UUID, timestamp: Instant, value: String)

object Data:
    given Codec[Data] = Codec.derive[Data]

The obvious benefit for Scala development is that dealing with Java types is no longer needed. Further in the article:

  • Vulcan example
  • Codec.encode and Codec.decode
  • Serializers and deserializers
  • Implementing a Serde
  • Caveats

To wrap up, we have explored the functionalities provided by Vulcan and implemented a way to integrate it with Kafka APIs that expect Serializer and Deserializer since Vulcan does not support this out of the box.

[Read More]

Tags apache java messaging app-development streaming scala