Flink有以下几种Environment
- 批处理Environment,ExecutionEnvironment
1 | ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); |
2.流处理Environment,StreamExecutionEnvironment
1 | StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); |
- 本机Environment,LocalEnvironment
1 | ExecutionEnvironment env = LocalEnvironment.getExecutionEnvironment(); |
- java集合Environment,CollectionEnvironment
1 | ExecutionEnvironment env = CollectionEnvironment.getExecutionEnvironment(); |
Ref
1 | https://www.yuque.com/cuteximi/base/flink-02?language=en-us |
创建Environment的方法
- getExecutionEnvironment ,含义就是本地运行就是
createLocalEnvironment,如果是通过client提交到集群上,就返回集群的环境
1 | Creates an execution environment that represents the context in which the program is currently executed. |
Ref
1 | https://github.com/apache/flink/blob/master/flink-java/src/main/java/org/apache/flink/api/java/ExecutionEnvironment.java |
2. createLocalEnvironment ,返回本地执行环境,需要在调用时指定默认的并行度,比如
1 | LocalStreamEnvironment env1 = StreamExecutionEnvironment.createLocalEnvironment(1); |
3. createRemoteEnvironment, 返回集群执行环境,将 Jar 提交到远程服务器。需要在调用时指定 JobManager 的 IP 和端口号,并指定要在集群中运行的 Jar 包,比如
1 | StreamExecutionEnvironment env1 = StreamExecutionEnvironment.createRemoteEnvironment("127.0.0.1", 8080, "/path/word_count.jar"); |