• Flink学习笔记——配置


    在Flink任务中,需要加载外置配置参数到任务中,在Flink的开发文档中介绍了,Flink提供了一个名为 ParameterTool 的工具来解决这个问题

    Flink开发文档:

    https://github.com/apache/flink/blob/master/docs/dev/application_parameters.zh.md
    

    其引入配置的方式有3种:

    1. From .properties files

    String propertiesFilePath = "/home/sam/flink/myjob.properties";
    ParameterTool parameter = ParameterTool.fromPropertiesFile(propertiesFilePath);
    

    2. From the command line arguments

    在args中添加 

    --input hdfs:///mydata --elements 42
    

    在代码中使用

    public static void main(String[] args) {
    
            // parse input arguments
            final ParameterTool parameterTool = ParameterTool.fromArgs(args);
    }
    

    3. From system properties

    使用

    -Dinput=hdfs:///mydata
    

    或者

    ParameterTool parameter = ParameterTool.fromSystemProperties();
    

    ParameterTool有如下几个方法可以获得参数

    parameter.getRequired("input");
    parameter.get("output", "myDefaultValue");
    parameter.getLong("expectedCount", -1L);
    parameter.getNumberOfParameters();
    

      

    注册全局变量

    // parse input arguments
    ParameterTool parameters = ParameterTool.fromSystemProperties();
    // register the parameters globally
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    env.getConfig().setGlobalJobParameters(parameters);
    

      

    下面使用第1种方法来配置Flink消费Kafka的Topic

    Ref:

    https://github.com/apache/flink/blob/master/flink-end-to-end-tests/flink-streaming-kafka-test-base/src/main/java/org/apache/flink/streaming/kafka/test/base/KafkaExampleUtil.java
    

      

  • 相关阅读:
    Python利用Remove.bg接口自动消除图片背景
    解决ajxa跨域问题
    CentOS7 修改静态IP
    CentOS下 安装composer 与tp5.1
    centon 安装php-fpm+Nginx
    win10 安装selenium和使用
    Scrapy 爬虫框架入门
    Python 异常处理
    selenium和phantomjs的介绍
    MongoDB入门
  • 原文地址:https://www.cnblogs.com/tonglin0325/p/14115069.html
Copyright © 2020-2023  润新知