apache geode项目结构_Apache Flink-基于Java项目模板创建Flink应用(流计算和批计算)...
Apache Flink創建模板項目有2種方式:
1. 通過Maven archetype命令創建;
2. 通過Flink 提供的Quickstart shell腳本創建;
關于Apache Flink的環境搭建,請參考相關鏈接:
Apache Flink快速入門-基本架構、核心概念和運行流程
Apache Flink v1.8 本地單機環境安裝和運行Flink應用
1. 通過Maven archetype創建Flink項目
#使用Maven創建
mvn archetype:generate
-DarchetypeGroupId=org.apache.flink
-DarchetypeArtifactId=flink-quickstart-java
-DarchetypeVersion=1.8.0
-DgroupId=com.rickie
-DartifactId=flink-tutorial
-Dversion=0.1
-Dpackage=com.rickie.tutorial
-DinteractiveMode=false
參數說明:
原型archetype有關參數表
項目相關參數:
通過上述mvn 命令創建的Java模板項目結構。
從上述項目結構可以看出,該項目是一個比較完善的Maven項目,其中Java代碼部分,BatchJob.java和StreamingJob.java 分別對應Flink 批量接口DataSet的實例代碼和流式接口DataStream的實例代碼。
2. 編寫業務代碼
將上述項目導入到IDEA中,Flink應用程序模板如下圖所示。
打開StreamingJob.java文件,實現簡單的單詞統計(Word Count)業務功能。
具體代碼如下所示。
package com.rickie.tutorial;
import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.windowing.time.Time;
import org.apache.flink.util.Collector;
/**
* Skeleton for a Flink Streaming Job.
*
*
For a tutorial how to write a Flink streaming application, check the
* tutorials and examples on the Flink Website.
*
*
To package your application into a JAR file for execution, run
* 'mvn clean package' on the command line.
*
*
If you change the name of the main class (with the public static void main(String[] args))
* method, change the respective entry in the POM.xml file (simply search for 'mainClass').
*/
public class StreamingJob {
public static void main(String[] args) throws Exception {
// set up the streaming execution environment
// 設置streaming運行環境
final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
// 連接socket獲取輸入的數據
DataStream text = env.socketTextStream("127.0.0.1
總結
以上是生活随笔為你收集整理的apache geode项目结构_Apache Flink-基于Java项目模板创建Flink应用(流计算和批计算)...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 创业板年报必须预告吗?
- 下一篇: python中列表和元组的相同点和不同点