IN - type of the records written to Kafka@PublicEvolving public class KafkaSinkBuilder<IN> extends Object
KafkaSink.
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 DeliveryGuarantee by using setDeliveryGuarantee(DeliveryGuarantee) but keep in mind when using DeliveryGuarantee.EXACTLY_ONCE one must set the transactionalIdPrefix setTransactionalIdPrefix(String).
| 限定符和类型 | 方法和说明 |
|---|---|
KafkaSink<IN> |
build()
Constructs the
KafkaSink with the configured properties. |
KafkaSinkBuilder<IN> |
setBootstrapServers(String bootstrapServers)
Sets the Kafka bootstrap servers.
|
KafkaSinkBuilder<IN> |
setDeliverGuarantee(org.apache.flink.connector.base.DeliveryGuarantee deliveryGuarantee)
已过时。
Will be removed in future versions. Use
setDeliveryGuarantee(org.apache.flink.connector.base.DeliveryGuarantee) instead. |
KafkaSinkBuilder<IN> |
setDeliveryGuarantee(org.apache.flink.connector.base.DeliveryGuarantee deliveryGuarantee)
Sets the wanted the
DeliveryGuarantee. |
KafkaSinkBuilder<IN> |
setKafkaProducerConfig(Properties props)
Sets the configuration which used to instantiate all used
KafkaProducer. |
KafkaSinkBuilder<IN> |
setProperty(String key,
String value) |
KafkaSinkBuilder<IN> |
setRecordSerializer(KafkaRecordSerializationSchema<IN> recordSerializer)
Sets the
KafkaRecordSerializationSchema that transforms incoming records to ProducerRecords. |
KafkaSinkBuilder<IN> |
setTransactionalIdPrefix(String transactionalIdPrefix)
Sets the prefix for all created transactionalIds if
DeliveryGuarantee.EXACTLY_ONCE is
configured. |
public KafkaSinkBuilder<IN> setDeliveryGuarantee(org.apache.flink.connector.base.DeliveryGuarantee deliveryGuarantee)
DeliveryGuarantee. The default delivery guarantee is deliveryGuarantee.deliveryGuarantee - KafkaSinkBuilder@Deprecated public KafkaSinkBuilder<IN> setDeliverGuarantee(org.apache.flink.connector.base.DeliveryGuarantee deliveryGuarantee)
setDeliveryGuarantee(org.apache.flink.connector.base.DeliveryGuarantee) instead.DeliveryGuarantee. The default delivery guarantee is deliveryGuarantee.deliveryGuarantee - KafkaSinkBuilderpublic KafkaSinkBuilder<IN> setKafkaProducerConfig(Properties props)
KafkaProducer.props - KafkaSinkBuilderpublic KafkaSinkBuilder<IN> setProperty(String key, String value)
public KafkaSinkBuilder<IN> setRecordSerializer(KafkaRecordSerializationSchema<IN> recordSerializer)
KafkaRecordSerializationSchema that transforms incoming records to ProducerRecords.recordSerializer - KafkaSinkBuilderpublic KafkaSinkBuilder<IN> setTransactionalIdPrefix(String transactionalIdPrefix)
DeliveryGuarantee.EXACTLY_ONCE is
configured.
It is mandatory to always set this value with DeliveryGuarantee.EXACTLY_ONCE to
prevent corrupted transactions if multiple jobs using the KafkaSink run against the same
Kafka Cluster. The default prefix is transactionalIdPrefix.
The size of the prefix is capped by MAXIMUM_PREFIX_BYTES formatted 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.
transactionalIdPrefix - KafkaSinkBuilderpublic KafkaSinkBuilder<IN> setBootstrapServers(String bootstrapServers)
bootstrapServers - a comma separated list of valid URIs to reach the Kafka brokerKafkaSinkBuilderCopyright © 2014–2023 The Apache Software Foundation. All rights reserved.