Flink學習筆記——Environment
阿新 • • 發佈:2020-12-10
Flink有以下幾種Environment
1. 批處理Environment,ExecutionEnvironment
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
2.流處理Environment,StreamExecutionEnvironment
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
3. 本機Environment,LocalEnvironment
ExecutionEnvironment env = LocalEnvironment.getExecutionEnvironment();
4. java集合Environment,CollectionEnvironment
ExecutionEnvironment env = CollectionEnvironment.getExecutionEnvironment();
Ref
https://www.yuque.com/cuteximi/base/flink-02?language=en-us
建立Environment的方法
1. getExecutionEnvironment ,含義就是本地執行就是createLocalEnvironment,如果是通過client提交到叢集上,就返回叢集的環境
Creates an execution environment that represents the context in which the program is currently executed. * If the program is invoked standalone, this method returns a local execution environment, as returned by * {@link #createLocalEnvironment()}. If the program is invoked from within the command line client to be * submitted to a cluster, this method returns the execution environment of this cluster.
Ref
https://github.com/apache/flink/blob/master/flink-java/src/main/java/org/apache/flink/api/java/ExecutionEnvironment.java
2.createLocalEnvironment ,返回本地執行環境,需要在呼叫時指定預設的並行度,比如
LocalStreamEnvironment env1 = StreamExecutionEnvironment.createLocalEnvironment(1); LocalEnvironment env2 = ExecutionEnvironment.createLocalEnvironment(1);
3.createRemoteEnvironment,返回叢集執行環境,將 Jar 提交到遠端伺服器。需要在呼叫時指定 JobManager 的 IP 和埠號,並指定要在叢集中執行的 Jar 包,比如
StreamExecutionEnvironment env1 = StreamExecutionEnvironment.createRemoteEnvironment("127.0.0.1", 8080, "/path/word_count.jar"); ExecutionEnvironment env2 = ExecutionEnvironment.createRemoteEnvironment("127.0.0.1", 8080, "/path/word_count.jar");