Interface KafkaRecordSerializationSchema<T>

  • Type Parameters:
    T - the type of values being serialized
    All Superinterfaces:
    Serializable

    @PublicEvolving
    public interface KafkaRecordSerializationSchema<T>
    extends Serializable
    A serialization schema which defines how to convert a value of type T to ProducerRecord.
    • Method Detail

      • open

        default void open​(org.apache.flink.api.common.serialization.SerializationSchema.InitializationContext context,
                          KafkaRecordSerializationSchema.KafkaSinkContext sinkContext)
                   throws Exception
        Initialization method for the schema. It is called before the actual working methods serialize(Object, KafkaSinkContext, 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.
        sinkContext - runtime information i.e. partitions, subtaskId
        Throws:
        Exception
      • serialize

        @Nullable
        org.apache.kafka.clients.producer.ProducerRecord<byte[],​byte[]> serialize​(T element,
                                                                                        KafkaRecordSerializationSchema.KafkaSinkContext context,
                                                                                        Long timestamp)
        Serializes given element and returns it as a ProducerRecord.
        Parameters:
        element - element to be serialized
        context - context to possibly determine target partition
        timestamp - timestamp
        Returns:
        Kafka ProducerRecord or null if the given element cannot be serialized