Class KafkaRecordSerializationSchemaBuilder<IN>
- java.lang.Object
-
- org.apache.flink.connector.kafka.sink.KafkaRecordSerializationSchemaBuilder<IN>
-
- Type Parameters:
IN- type of records to be serialized
@PublicEvolving public class KafkaRecordSerializationSchemaBuilder<IN> extends Object
Builder to constructKafkaRecordSerializationSchema.This class should give a first entrypoint when trying to serialize elements to
ProducerRecord. The following examples show some of the possibilities.Simple key-value serialization:
KafkaRecordSerializationSchema.builder() .setTopic("topic) .setKeySerializationSchema(new SimpleStringSchema()) .setValueSerializationSchema(new SimpleStringSchema()) .build()Using Kafka's serialization stack:
KafkaRecordSerializationSchema.builder() .setTopic("topic) .setKeySerializer(StringSerializer.class) .setKafkaValueSerializer(StringSerializer.class) .build()With custom partitioner:
KafkaRecordSerializationSchema.builder() .setTopic("topic) .setPartitioner(MY_FLINK_PARTITIONER) .setValueSerializationSchema(StringSerializer.class) .build()The different serialization methods for key and value are mutually exclusive thus i.e. it is not possible to use
setKeySerializationSchema(SerializationSchema)andsetKafkaKeySerializer(Class)on the same builder instance.It is necessary to configure exactly one serialization method for the value and a topic.
- See Also:
KafkaRecordSerializationSchema.builder()
-
-
Constructor Summary
Constructors Constructor Description KafkaRecordSerializationSchemaBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description KafkaRecordSerializationSchema<IN>build()Constructs theKafkaRecordSerializationSchemaBuilderwith the configured properties.<T extends IN>
KafkaRecordSerializationSchemaBuilder<T>setKafkaKeySerializer(Class<? extends org.apache.kafka.common.serialization.Serializer<? super T>> keySerializer)Sets Kafka'sSerializerto serialize incoming elements to the key of theProducerRecord.<T extends IN,S extends org.apache.kafka.common.serialization.Serializer<? super T>>
KafkaRecordSerializationSchemaBuilder<T>setKafkaKeySerializer(Class<S> keySerializer, Map<String,String> configuration)Sets a configurable KafkaSerializerand pass a configuration to serialize incoming elements to the key of theProducerRecord.<T extends IN>
KafkaRecordSerializationSchemaBuilder<T>setKafkaValueSerializer(Class<? extends org.apache.kafka.common.serialization.Serializer<? super T>> valueSerializer)Sets Kafka'sSerializerto serialize incoming elements to the value of theProducerRecord.<T extends IN,S extends org.apache.kafka.common.serialization.Serializer<? super T>>
KafkaRecordSerializationSchemaBuilder<T>setKafkaValueSerializer(Class<S> valueSerializer, Map<String,String> configuration)Sets a configurable KafkaSerializerand pass a configuration to serialize incoming elements to the value of theProducerRecord.<T extends IN>
KafkaRecordSerializationSchemaBuilder<T>setKeySerializationSchema(org.apache.flink.api.common.serialization.SerializationSchema<? super T> keySerializationSchema)Sets aSerializationSchemawhich is used to serialize the incoming element to the key of theProducerRecord.<T extends IN>
KafkaRecordSerializationSchemaBuilder<T>setPartitioner(FlinkKafkaPartitioner<? super T> partitioner)Sets a custom partitioner determining the target partition of the target topic.KafkaRecordSerializationSchemaBuilder<IN>setTopic(String topic)Sets a fixed topic which used as destination for all records.<T extends IN>
KafkaRecordSerializationSchemaBuilder<T>setTopicSelector(TopicSelector<? super T> topicSelector)Sets a topic selector which computes the target topic for every incoming record.<T extends IN>
KafkaRecordSerializationSchemaBuilder<T>setValueSerializationSchema(org.apache.flink.api.common.serialization.SerializationSchema<T> valueSerializationSchema)Sets aSerializationSchemawhich is used to serialize the incoming element to the value of theProducerRecord.
-
-
-
Method Detail
-
setPartitioner
public <T extends IN> KafkaRecordSerializationSchemaBuilder<T> setPartitioner(FlinkKafkaPartitioner<? super T> partitioner)
Sets a custom partitioner determining the target partition of the target topic.- Parameters:
partitioner-- Returns:
this
-
setTopic
public KafkaRecordSerializationSchemaBuilder<IN> setTopic(String topic)
Sets a fixed topic which used as destination for all records.- Parameters:
topic-- Returns:
this
-
setTopicSelector
public <T extends IN> KafkaRecordSerializationSchemaBuilder<T> setTopicSelector(TopicSelector<? super T> topicSelector)
Sets a topic selector which computes the target topic for every incoming record.- Parameters:
topicSelector-- Returns:
this
-
setKeySerializationSchema
public <T extends IN> KafkaRecordSerializationSchemaBuilder<T> setKeySerializationSchema(org.apache.flink.api.common.serialization.SerializationSchema<? super T> keySerializationSchema)
Sets aSerializationSchemawhich is used to serialize the incoming element to the key of theProducerRecord.- Parameters:
keySerializationSchema-- Returns:
this
-
setKafkaKeySerializer
public <T extends IN> KafkaRecordSerializationSchemaBuilder<T> setKafkaKeySerializer(Class<? extends org.apache.kafka.common.serialization.Serializer<? super T>> keySerializer)
Sets Kafka'sSerializerto serialize incoming elements to the key of theProducerRecord.- Parameters:
keySerializer-- Returns:
this
-
setKafkaKeySerializer
public <T extends IN,S extends org.apache.kafka.common.serialization.Serializer<? super T>> KafkaRecordSerializationSchemaBuilder<T> setKafkaKeySerializer(Class<S> keySerializer, Map<String,String> configuration)
Sets a configurable KafkaSerializerand pass a configuration to serialize incoming elements to the key of theProducerRecord.- Type Parameters:
S- type of the used serializer class- Parameters:
keySerializer-configuration-- Returns:
this
-
setValueSerializationSchema
public <T extends IN> KafkaRecordSerializationSchemaBuilder<T> setValueSerializationSchema(org.apache.flink.api.common.serialization.SerializationSchema<T> valueSerializationSchema)
Sets aSerializationSchemawhich is used to serialize the incoming element to the value of theProducerRecord.- Parameters:
valueSerializationSchema-- Returns:
this
-
setKafkaValueSerializer
public <T extends IN> KafkaRecordSerializationSchemaBuilder<T> setKafkaValueSerializer(Class<? extends org.apache.kafka.common.serialization.Serializer<? super T>> valueSerializer)
Sets Kafka'sSerializerto serialize incoming elements to the value of theProducerRecord.- Parameters:
valueSerializer-- Returns:
this
-
setKafkaValueSerializer
public <T extends IN,S extends org.apache.kafka.common.serialization.Serializer<? super T>> KafkaRecordSerializationSchemaBuilder<T> setKafkaValueSerializer(Class<S> valueSerializer, Map<String,String> configuration)
Sets a configurable KafkaSerializerand pass a configuration to serialize incoming elements to the value of theProducerRecord.- Type Parameters:
S- type of the used serializer class- Parameters:
valueSerializer-configuration-- Returns:
this
-
build
public KafkaRecordSerializationSchema<IN> build()
Constructs theKafkaRecordSerializationSchemaBuilderwith the configured properties.- Returns:
KafkaRecordSerializationSchema
-
-