All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.thake.kafka.avro4k.serializer.KafkaAvro4kSerializer.kt Maven / Gradle / Ivy

There is a newer version: 0.14.0
Show newest version
package com.github.thake.kafka.avro4k.serializer

import io.confluent.kafka.schemaregistry.avro.AvroSchema
import io.confluent.kafka.schemaregistry.client.SchemaRegistryClient
import org.apache.kafka.common.serialization.Serializer

class KafkaAvro4kSerializer(
    client : SchemaRegistryClient? = null,
    props : Map? = null
) : AbstractKafkaAvro4kSerializer(), Serializer {
    private var isKey = false

    init {
        props?.let { configure(this.serializerConfig(it)) }
        //Set the registry client explicitly after configuration has been applied to override client from configuration
        if (client != null) this.schemaRegistry = client
    }

    override fun configure(configs: Map, isKey: Boolean) {
        this.isKey = isKey
        this.configure(KafkaAvro4kSerializerConfig(configs))
    }


    override fun serialize(topic: String, record: Any?): ByteArray? {
        return this.serializeImpl(
            this.getSubjectName(
                topic,
                isKey,
                record,
                AvroSchema(avroSchemaUtils.getSchema(record))
            ), record
        )
    }

    override fun close() {}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy