赞
踩
目录
从开发步骤的角度来讲,主要分为四大部分 :
没说的,两行代码解决全部
批:
ExecutionEnvironment benv = ExecutionEnvironment.getExecutionEnvironment();
流:
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
为了更好的方便敲代码,一个导包,一个JavaBean类
- <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
- <dependency>
- <groupId>org.projectlombok</groupId>
- <artifactId>lombok</artifactId>
- <version>1.18.16</version>
- </dependency>
- import lombok.AllArgsConstructor;
- import lombok.Data;
- import lombok.NoArgsConstructor;
-
- /**
- * 水位传感器:用于接收水位数据
- *
- * id:传感器编号
- * ts:时间戳
- * vc:水位
- */
- @Data
- @NoArgsConstructor
- @AllArgsConstructor
- public class WaterSensor {
- private String id;
- private Long ts;
- private Integer vc;
- }
- public class SourceJava {
- public static void main(String[] args) throws Exception {
- //1.获取流的执行环境
- StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
-
- env.setParallelism(1);
-
- //2.TODO 从集合中读取数据
- List<Integer> list = Arrays.asList(1, 2, 3, 4, 5);
- DataStreamSource<Integer> streamSource = env.fromCollection(list);
-
- //从元素中读取数据
- DataStreamSource<String> dataStreamSource = env.fromElements("a",
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。