Flink学习笔记——Environment

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");

  

 

posted @ 2020-12-10 20:06  tonglin0325  阅读(1597)  评论(0编辑  收藏  举报