/*
* 从Kafka读取数据处理完毕写入Redis
*/
public class KafkaToRedis {
public static void main(String[] args) throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
//开启checkpointing
env.enableCheckpointing(1000);
//设置StateBackEnd 存储在HDFS中
env.setStateBackend(new FsStateBackend("hdfs://mydfs/checkpoint"));
//设置cancel任务checkpoint数据的策略 cancel任务保留checkpoint的数据
env.getCheckpointConfig().enableExternalizedCheckpoints(CheckpointConfig.ExternalizedCheckpointCleanup.RETAIN_ON_CANCELLATION);
Properties properties = new Properties();
//设置Broker地址
properties.setProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG,"linux01:9092,linux02:9092,linux03:9092");
//设置没有偏移量的话从头开始读取数据
properties.setProperty(ConsumerConfig.AUTO_OFFSET_RESET_DOC,"earliest");
//设置不自动提交偏移量
properties.setProperty(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG,"false");
flink读取kafka的数据处理完毕写入redis
最新推荐文章于 2024-09-27 18:40:09 发布