MAPREDUCE服务 MRS-Kafka表开发建议:为保证数据准确性将同key数据写入Kafka的同一个分区

时间:2024-11-22 09:36:13

为保证数据准确性将同key数据写入Kafka的同一个分区

Flink写Kafka使用fixed策略,并在写入之前根据key进行Hash。

【示例】

CREATE TABLE kafka (
 f_sequence INT,
 f_sequence1 INT,
 f_sequence2 INT,
 f_sequence3 INT 
 ) WITH ( 
 'connector' = 'kafka',
 'topic' = 'yxtest123',
 'properties.bootstrap.servers' = '192.168.0.104:9092',
 'properties.group.id' = 'testGroup1',
 'scan.startup.mode' = 'latest-offset',
 'format' = 'json',
 'sink.partitioner'='fixed'
 ); 

 insert into kafka select /*+ DISTRIBUTEBY('f_sequence','f_sequence1') */ * from datagen;
support.huaweicloud.com/devg-rule-mrs/mrs_07_450151.html