Class VeniceAvroKafkaSerializer

  • All Implemented Interfaces:
    VeniceKafkaSerializer<java.lang.Object>, java.io.Closeable, java.lang.AutoCloseable, org.apache.kafka.common.serialization.Deserializer<java.lang.Object>, org.apache.kafka.common.serialization.Serializer<java.lang.Object>

    public class VeniceAvroKafkaSerializer
    extends java.lang.Object
    implements VeniceKafkaSerializer<java.lang.Object>
    This class is a thin wrapper of AvroSerializer and AvroGenericDeserializer. It is necessary to have a separate class responsible for this in this module in order to implement Kafka's interface, which is a dependency we do not want to leak into the schema-common module where the two above classes are located.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Close this serializer.
      void configure​(java.util.Map<java.lang.String,​?> configMap, boolean isKey)
      Configure this class.
      java.lang.Object deserialize​(byte[] bytes)  
      java.lang.Object deserialize​(java.lang.String topic, byte[] bytes)
      Create an object from an array of bytes
      java.lang.Object deserialize​(java.nio.ByteBuffer byteBuffer)  
      byte[] serialize​(java.lang.String topic, java.lang.Object object)
      Construct an array of bytes from the given object
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface org.apache.kafka.common.serialization.Deserializer

        deserialize
      • Methods inherited from interface org.apache.kafka.common.serialization.Serializer

        serialize
    • Constructor Detail

      • VeniceAvroKafkaSerializer

        public VeniceAvroKafkaSerializer​(java.lang.String schemaStr)
      • VeniceAvroKafkaSerializer

        public VeniceAvroKafkaSerializer​(org.apache.avro.Schema schema)
    • Method Detail

      • close

        public void close()
        Close this serializer. This method has to be idempotent if the serializer is used in KafkaProducer because it might be called multiple times.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in interface org.apache.kafka.common.serialization.Deserializer<java.lang.Object>
        Specified by:
        close in interface org.apache.kafka.common.serialization.Serializer<java.lang.Object>
        Specified by:
        close in interface VeniceKafkaSerializer<java.lang.Object>
      • configure

        public void configure​(java.util.Map<java.lang.String,​?> configMap,
                              boolean isKey)
        Configure this class.
        Specified by:
        configure in interface org.apache.kafka.common.serialization.Deserializer<java.lang.Object>
        Specified by:
        configure in interface org.apache.kafka.common.serialization.Serializer<java.lang.Object>
        Specified by:
        configure in interface VeniceKafkaSerializer<java.lang.Object>
        Parameters:
        configMap - configs in key/value pairs
        isKey - whether is for key or value
      • serialize

        public byte[] serialize​(java.lang.String topic,
                                java.lang.Object object)
        Description copied from interface: VeniceKafkaSerializer
        Construct an array of bytes from the given object
        Specified by:
        serialize in interface org.apache.kafka.common.serialization.Serializer<java.lang.Object>
        Specified by:
        serialize in interface VeniceKafkaSerializer<java.lang.Object>
        Parameters:
        topic - Topic to which the object belongs.
        object - The object
        Returns:
        The bytes taken from the object
      • deserialize

        public java.lang.Object deserialize​(java.lang.String topic,
                                            byte[] bytes)
        Description copied from interface: VeniceKafkaSerializer
        Create an object from an array of bytes
        Specified by:
        deserialize in interface org.apache.kafka.common.serialization.Deserializer<java.lang.Object>
        Specified by:
        deserialize in interface VeniceKafkaSerializer<java.lang.Object>
        Parameters:
        topic - Topic to which the array of bytes belongs.
        bytes - An array of bytes with the objects data
        Returns:
        A java object serialzed from the bytes
      • deserialize

        public java.lang.Object deserialize​(byte[] bytes)
      • deserialize

        public java.lang.Object deserialize​(java.nio.ByteBuffer byteBuffer)