Apache flink 如何在数据流程序中配置用户函数?

Apache flink 如何在数据流程序中配置用户函数?,apache-flink,Apache Flink,我创建了一个带有配置的流媒体环境,并尝试在RichMapFunction的open()方法中访问此配置 例如: Configuration conf = new Configuration(); conf.setBoolean("a", true); StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironment(8, conf); DataS

我创建了一个带有配置的流媒体环境,并尝试在
RichMapFunction
open()
方法中访问此配置

例如:

    Configuration conf = new Configuration();
    conf.setBoolean("a", true);
    StreamExecutionEnvironment env = 
        StreamExecutionEnvironment.createLocalEnvironment(8, conf);

    DataStreamSource<Integer> source = env.fromElements(5,5,5,5,5);
    source.map(new RichMapFunction<Integer, Integer>() {

        @Override
        public void open(Configuration parameters) throws Exception {
            boolean a = parameters.getBoolean("a", false);
            super.open(parameters);
        }

        @Override
        public Integer map(Integer value) throws Exception {
            return value;
        }
    }).print();

    env.execute();
Configuration conf=new Configuration();
conf.setBoolean(“a”,真);
StreamExecutionEnvironment环境=
StreamExecutionEnvironment.createLocalEnvironment(8,conf);
DataStreamSource source=env.fromElements(5,5,5,5);
map(新的RichMapFunction(){
@凌驾
公共void open(配置参数)引发异常{
布尔a=参数。getBoolean(“a”,false);
super.open(参数);
}
@凌驾
公共整数映射(整数值)引发异常{
返回值;
}
}).print();
execute();
但是,在调试
open()
方法时,我发现配置为空


我做错了什么?如何在流媒体环境中将配置正确地传递给
RichFunction

Flink的DataStream和DataSet API共享相同的用户功能界面,如示例中的
RichMapFunction


Flink的
RichFunction
open
方法的
Configuration
参数是DataSet API的第一个版本遗留下来的,未在DataStream API中使用。Flink序列化您在
map()
调用中提供的对象,并将其发送给并行工作程序。因此,可以将对象中的参数直接设置为常规字段。

您可能需要考虑使用此信息更新文档。所有最新的文档都显示了一个带有参数的
方法,但是在哪里都找不到。是的,说得好。它已经为下一个版本(1.4)进行了更新。不确定为什么修复程序没有后端口到1.3分支。