Successor to deprecated FlinkKafkaProducer

Solution 1:

FlinkKafkaProducer has been deprecated

Flink recommends using the new source and sink api in the latest version

Reference to https://nightlies.apache.org/flink/flink-docs-master/docs/connectors/datastream/kafka/

DataStream<String> stream = ...
        
KafkaSink<String> sink = KafkaSink.<String>builder()
        .setBootstrapServers(brokers)
        .setRecordSerializer(KafkaRecordSerializationSchema.builder()
            .setTopic("topic-name")
            .setValueSerializationSchema(new SimpleStringSchema())
            .build()
        )
        .setDeliverGuarantee(DeliveryGuarantee.AT_LEAST_ONCE)
        .build();
        
stream.sinkTo(sink);