Class KafkaSinkBuilder<IN>
- java.lang.Object
-
- org.apache.flink.connector.kafka.sink.KafkaSinkBuilder<IN>
-
- Type Parameters:
IN- type of the records written to Kafka
@PublicEvolving public class KafkaSinkBuilder<IN> extends Object
Builder to constructKafkaSink.The following example shows the minimum setup to create a KafkaSink that writes String values to a Kafka topic.
KafkaSink<String> sink = KafkaSink .<String>builder .setBootstrapServers(MY_BOOTSTRAP_SERVERS) .setRecordSerializer(MY_RECORD_SERIALIZER) .build();One can also configure different
DeliveryGuaranteeby usingsetDeliveryGuarantee(DeliveryGuarantee)but keep in mind when usingDeliveryGuarantee.EXACTLY_ONCEone must set the transactionalIdPrefixsetTransactionalIdPrefix(String).
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description KafkaSink<IN>build()Constructs theKafkaSinkwith the configured properties.KafkaSinkBuilder<IN>setBootstrapServers(String bootstrapServers)Sets the Kafka bootstrap servers.KafkaSinkBuilder<IN>setDeliverGuarantee(org.apache.flink.connector.base.DeliveryGuarantee deliveryGuarantee)Deprecated.Will be removed in future versions.KafkaSinkBuilder<IN>setDeliveryGuarantee(org.apache.flink.connector.base.DeliveryGuarantee deliveryGuarantee)Sets the wanted theDeliveryGuarantee.KafkaSinkBuilder<IN>setKafkaProducerConfig(Properties props)Sets the configuration which used to instantiate all usedKafkaProducer.KafkaSinkBuilder<IN>setProperty(String key, String value)KafkaSinkBuilder<IN>setRecordSerializer(KafkaRecordSerializationSchema<IN> recordSerializer)Sets theKafkaRecordSerializationSchemathat transforms incoming records toProducerRecords.KafkaSinkBuilder<IN>setTransactionalIdPrefix(String transactionalIdPrefix)Sets the prefix for all created transactionalIds ifDeliveryGuarantee.EXACTLY_ONCEis configured.
-
-
-
Method Detail
-
setDeliveryGuarantee
public KafkaSinkBuilder<IN> setDeliveryGuarantee(org.apache.flink.connector.base.DeliveryGuarantee deliveryGuarantee)
Sets the wanted theDeliveryGuarantee. The default delivery guarantee isdeliveryGuarantee.- Parameters:
deliveryGuarantee-- Returns:
KafkaSinkBuilder
-
setDeliverGuarantee
@Deprecated public KafkaSinkBuilder<IN> setDeliverGuarantee(org.apache.flink.connector.base.DeliveryGuarantee deliveryGuarantee)
Deprecated.Will be removed in future versions. UsesetDeliveryGuarantee(org.apache.flink.connector.base.DeliveryGuarantee)instead.Sets the wanted theDeliveryGuarantee. The default delivery guarantee isdeliveryGuarantee.- Parameters:
deliveryGuarantee-- Returns:
KafkaSinkBuilder
-
setKafkaProducerConfig
public KafkaSinkBuilder<IN> setKafkaProducerConfig(Properties props)
Sets the configuration which used to instantiate all usedKafkaProducer.- Parameters:
props-- Returns:
KafkaSinkBuilder
-
setProperty
public KafkaSinkBuilder<IN> setProperty(String key, String value)
-
setRecordSerializer
public KafkaSinkBuilder<IN> setRecordSerializer(KafkaRecordSerializationSchema<IN> recordSerializer)
Sets theKafkaRecordSerializationSchemathat transforms incoming records toProducerRecords.- Parameters:
recordSerializer-- Returns:
KafkaSinkBuilder
-
setTransactionalIdPrefix
public KafkaSinkBuilder<IN> setTransactionalIdPrefix(String transactionalIdPrefix)
Sets the prefix for all created transactionalIds ifDeliveryGuarantee.EXACTLY_ONCEis configured.It is mandatory to always set this value with
DeliveryGuarantee.EXACTLY_ONCEto prevent corrupted transactions if multiple jobs using the KafkaSink run against the same Kafka Cluster. The default prefix istransactionalIdPrefix.The size of the prefix is capped by
MAXIMUM_PREFIX_BYTESformatted with UTF-8.It is important to keep the prefix stable across application restarts. If the prefix changes it might happen that lingering transactions are not correctly aborted and newly written messages are not immediately consumable until the transactions timeout.
- Parameters:
transactionalIdPrefix-- Returns:
KafkaSinkBuilder
-
setBootstrapServers
public KafkaSinkBuilder<IN> setBootstrapServers(String bootstrapServers)
Sets the Kafka bootstrap servers.- Parameters:
bootstrapServers- a comma separated list of valid URIs to reach the Kafka broker- Returns:
KafkaSinkBuilder
-
-