Interface KafkaSerializationSchema<T>

  • Type Parameters:
    T - the type of values being serialized
    All Superinterfaces:
    Serializable
    All Known Implementing Classes:
    KafkaSerializationSchemaWrapper

    @PublicEvolving
    public interface KafkaSerializationSchema<T>
    extends Serializable
    A KafkaSerializationSchema defines how to serialize values of type T into ProducerRecords.

    Please also implement KafkaContextAware if your serialization schema needs information about the available partitions and the number of parallel subtasks along with the subtask ID on which the Kafka Producer is running.

    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default void open​(org.apache.flink.api.common.serialization.SerializationSchema.InitializationContext context)
      Initialization method for the schema.
      org.apache.kafka.clients.producer.ProducerRecord<byte[],​byte[]> serialize​(T element, Long timestamp)
      Serializes given element and returns it as a ProducerRecord.
    • Method Detail

      • open

        default void open​(org.apache.flink.api.common.serialization.SerializationSchema.InitializationContext context)
                   throws Exception
        Initialization method for the schema. It is called before the actual working methods serialize(Object, Long) and thus suitable for one time setup work.

        The provided SerializationSchema.InitializationContext can be used to access additional features such as e.g. registering user metrics.

        Parameters:
        context - Contextual information that can be used during initialization.
        Throws:
        Exception
      • serialize

        org.apache.kafka.clients.producer.ProducerRecord<byte[],​byte[]> serialize​(T element,
                                                                                        @Nullable
                                                                                        Long timestamp)
        Serializes given element and returns it as a ProducerRecord.
        Parameters:
        element - element to be serialized
        timestamp - timestamp (can be null)
        Returns:
        Kafka ProducerRecord