我想设置flink kafka kafka生产者smantic.exactly_once,我正在使用scala代码如下
alertEnrichStream.map(_.toJsonStr)
.addSink(
new FlinkKafkaProducer011(
kafkaBrokers,
kafkaOutputTopic,
new SimpleStringSchema))
如何编辑代码设置语义?
使用可以定义语义的构造函数。像这样:
FlinkKafkaProducer011<Integer> kafkaProducer = new FlinkKafkaProducer011<>(
topic,
new SimpleStringSchema,
properties,
Semantic.EXACTLY_ONCE);
我想出了这位讲师的用法,而且效果很好:
val producerProps = new Properties
producerProps.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers)
producerProps.setProperty(ProducerConfig.RETRIES_CONFIG, "2147483647")
producerProps.setProperty(ProducerConfig.MAX_IN_FLIGHT_REQUESTS_PER_CONNECTION, "1")
producerProps.setProperty(ProducerConfig.ACKS_CONFIG, "all")
producerProps.setProperty(ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG, "true")
new FlinkKafkaProducer011[String](
topic,
new KeyedSerializationSchemaWrapper[String](new SimpleStringSchema),
producerProps,
Optional.of(new FlinkFixedPartitioner[String]),
FlinkKafkaProducer011.Semantic.EXACTLY_ONCE,
10
)