Search in sources :

Example 1 with FlinkFixedPartitioner

use of org.apache.flink.streaming.connectors.kafka.partitioner.FlinkFixedPartitioner in project flink by apache.

the class KafkaChangelogTableITCase method writeRecordsToKafka.

private void writeRecordsToKafka(String topic, List<String> lines) throws Exception {
    DataStreamSource<String> stream = env.fromCollection(lines);
    SerializationSchema<String> serSchema = new SimpleStringSchema();
    FlinkKafkaPartitioner<String> partitioner = new FlinkFixedPartitioner<>();
    // the producer must not produce duplicates
    Properties producerProperties = getStandardProps();
    producerProperties.setProperty("retries", "0");
    stream.sinkTo(KafkaSink.<String>builder().setBootstrapServers(producerProperties.getProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG)).setRecordSerializer(KafkaRecordSerializationSchema.builder().setTopic(topic).setValueSerializationSchema(serSchema).setPartitioner(partitioner).build()).setDeliverGuarantee(DeliveryGuarantee.EXACTLY_ONCE).build());
    env.execute("Write sequence");
}
Also used : FlinkFixedPartitioner(org.apache.flink.streaming.connectors.kafka.partitioner.FlinkFixedPartitioner) SimpleStringSchema(org.apache.flink.api.common.serialization.SimpleStringSchema) Properties(java.util.Properties)

Aggregations

Properties (java.util.Properties)1 SimpleStringSchema (org.apache.flink.api.common.serialization.SimpleStringSchema)1 FlinkFixedPartitioner (org.apache.flink.streaming.connectors.kafka.partitioner.FlinkFixedPartitioner)1