IN
- type of records to be serialized@PublicEvolving public class KafkaRecordSerializationSchemaBuilder<IN> extends Object
KafkaRecordSerializationSchema
.
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)
and setKafkaKeySerializer(Class)
on the same builder instance.
It is necessary to configure exactly one serialization method for the value and a topic.
KafkaRecordSerializationSchema.builder()
Constructor and Description |
---|
KafkaRecordSerializationSchemaBuilder() |
Modifier and Type | Method and Description |
---|---|
KafkaRecordSerializationSchema<IN> |
build()
Constructs the
KafkaRecordSerializationSchemaBuilder with the configured properties. |
<T extends IN> |
setKafkaKeySerializer(Class<? extends org.apache.kafka.common.serialization.Serializer<? super T>> keySerializer)
Sets Kafka's
Serializer to serialize incoming elements to the key of the ProducerRecord . |
<T extends IN,S extends org.apache.kafka.common.serialization.Serializer<? super T>> |
setKafkaKeySerializer(Class<S> keySerializer,
Map<String,String> configuration)
Sets a configurable Kafka
Serializer and pass a configuration to serialize incoming
elements to the key of the ProducerRecord . |
<T extends IN> |
setKafkaValueSerializer(Class<? extends org.apache.kafka.common.serialization.Serializer<? super T>> valueSerializer)
Sets Kafka's
Serializer to serialize incoming elements to the value of the ProducerRecord . |
<T extends IN,S extends org.apache.kafka.common.serialization.Serializer<? super T>> |
setKafkaValueSerializer(Class<S> valueSerializer,
Map<String,String> configuration)
Sets a configurable Kafka
Serializer and pass a configuration to serialize incoming
elements to the value of the ProducerRecord . |
<T extends IN> |
setKeySerializationSchema(SerializationSchema<? super T> keySerializationSchema)
Sets a
SerializationSchema which is used to serialize the incoming element to the key
of the ProducerRecord . |
<T extends IN> |
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> |
setTopicSelector(TopicSelector<? super T> topicSelector)
Sets a topic selector which computes the target topic for every incoming record.
|
<T extends IN> |
setValueSerializationSchema(SerializationSchema<T> valueSerializationSchema)
Sets a
SerializationSchema which is used to serialize the incoming element to the
value of the ProducerRecord . |
public KafkaRecordSerializationSchemaBuilder()
public <T extends IN> KafkaRecordSerializationSchemaBuilder<T> setPartitioner(FlinkKafkaPartitioner<? super T> partitioner)
partitioner
- this
public KafkaRecordSerializationSchemaBuilder<IN> setTopic(String topic)
topic
- this
public <T extends IN> KafkaRecordSerializationSchemaBuilder<T> setTopicSelector(TopicSelector<? super T> topicSelector)
topicSelector
- this
public <T extends IN> KafkaRecordSerializationSchemaBuilder<T> setKeySerializationSchema(SerializationSchema<? super T> keySerializationSchema)
SerializationSchema
which is used to serialize the incoming element to the key
of the ProducerRecord
.keySerializationSchema
- this
public <T extends IN> KafkaRecordSerializationSchemaBuilder<T> setKafkaKeySerializer(Class<? extends org.apache.kafka.common.serialization.Serializer<? super T>> keySerializer)
Serializer
to serialize incoming elements to the key of the ProducerRecord
.keySerializer
- this
public <T extends IN,S extends org.apache.kafka.common.serialization.Serializer<? super T>> KafkaRecordSerializationSchemaBuilder<T> setKafkaKeySerializer(Class<S> keySerializer, Map<String,String> configuration)
Serializer
and pass a configuration to serialize incoming
elements to the key of the ProducerRecord
.S
- type of the used serializer classkeySerializer
- configuration
- this
public <T extends IN> KafkaRecordSerializationSchemaBuilder<T> setValueSerializationSchema(SerializationSchema<T> valueSerializationSchema)
SerializationSchema
which is used to serialize the incoming element to the
value of the ProducerRecord
.valueSerializationSchema
- this
public <T extends IN> KafkaRecordSerializationSchemaBuilder<T> setKafkaValueSerializer(Class<? extends org.apache.kafka.common.serialization.Serializer<? super T>> valueSerializer)
Serializer
to serialize incoming elements to the value of the ProducerRecord
.valueSerializer
- this
public <T extends IN,S extends org.apache.kafka.common.serialization.Serializer<? super T>> KafkaRecordSerializationSchemaBuilder<T> setKafkaValueSerializer(Class<S> valueSerializer, Map<String,String> configuration)
Serializer
and pass a configuration to serialize incoming
elements to the value of the ProducerRecord
.S
- type of the used serializer classvalueSerializer
- configuration
- this
public KafkaRecordSerializationSchema<IN> build()
KafkaRecordSerializationSchemaBuilder
with the configured properties.KafkaRecordSerializationSchema
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.