flink极简配置文件

使用flink自带的

 InputStream inputStream = ParameterTool.class.getClassLoader()
                .getResourceAsStream("application.properties");
        ParameterTool params = ParameterTool.fromPropertiesFile(inputStream);

// 1. 获取String类型参数(如果key不存在,返回null)
String input = params.get("input");

// 2. 获取String类型参数,如果key不存在,则使用提供的默认值
String output = params.get("output", "/tmp/default-output");

// 3. 获取必要参数,如果key不存在,抛出RuntimeException
String requiredParam = params.getRequired("db.url");

// 4. 获取其他基本类型参数(也支持默认值)
int maxParallelism = params.getInt("parallelism", 4);
long timeout = params.getLong("timeout.ms", 60000L);
float ratio = params.getFloat("ratio", 0.5f);
double threshold = params.getDouble("threshold", 0.9);
boolean enableFeature = params.getBoolean("feature.enabled", false);

// 5. 检查某个参数是否存在
if (params.has("debug.mode")) {
    // 调试逻辑
}

 

posted @ 2026-01-20 13:17  ---江北  阅读(4)  评论(0)    收藏  举报
TOP