当前位置:网站首页>Example of the task submitted by the Flink packer
Example of the task submitted by the Flink packer
2022-07-27 16:16:00 【Carrot eating crocodile】
Tools
maven、idea、flink1.9-2.11scala
Code
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.hctang.flink</groupId>
<artifactId>firstcode</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.flink/flink-scala -->
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-java</artifactId>
<version>1.9.0</version>
<scope>provided</scope>
<!--<scope>provided</scope>-->
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-java_2.11</artifactId>
<version>1.9.0</version>
<scope>provided</scope>
<!-- Specify the scope of the package , Running in a cluster , Many things don't need ,-->
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-scala_2.11</artifactId>
<version>1.9.0</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.flink/flink-streaming-scala -->
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-scala_2.11</artifactId>
<version>1.9.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Compile the plug-in -->
<plugin>scala
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- scala Compile the plug-in -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.1.6</version>
<configuration>
<scalaCompatVersion>2.11</scalaCompatVersion>
<scalaVersion>2.11.8</scalaVersion>
<encoding>UTF-8</encoding>
</configuration>
<executions>
<execution>
<id>compile-scala</id>
<phase>compile</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile-scala</id>
<phase>test-compile</phase>
<goals>
<goal>add-source</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- hit jar Package plugin ( Will contain all dependencies ) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<!-- You can set jar Package entry class ( Optional ) It can also be dynamically specified at runtime -->
<mainClass>hctang.tech.socketWindowwordCountScala</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
socketWindowwordCountScala
package hctang.tech
import org.apache.flink.api.java.utils.ParameterTool
import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment
import org.apache.flink.streaming.api.windowing.time.Time
object socketWindowwordCountScala {
def main(args: Array[String]): Unit = {
// obtain socket Port number
val port:Int=try{
ParameterTool.fromArgs(args).getInt("port")
}catch {
case e:Exception=>{
System.err.println("No port set. use default port 9000--scala")
}
9000
}
val env:StreamExecutionEnvironment=StreamExecutionEnvironment.getExecutionEnvironment
val text=env.socketTextStream("localhost",port,'\n')
import org.apache.flink.api.scala._
val windowCounts=text.flatMap(line =>line.split("\\s"))
.map(w => WordWithCount(w,1))
.keyBy("word")// grouping
.timeWindow(Time.seconds(2),Time.seconds(1))
.sum("count");
windowCounts.print.setParallelism(1);
windowCounts
env.execute("Socket window count")
}
case class WordWithCount(word: String,count: Long)
}
Start or shut down the cluster
./FLINK_HOME/bin/start-cluster.sh
./FLINK_HOME/bin/stop-cluster.sh
pack
Alt+F12 open idea The terminal input of maven clean package -DskipTests
In the engineering of target You can see the packed files in the directory
Such as :firstcode-1.0-SNAPSHOT-jar-with-dependencies.jar
Submit
./FLINK_HOME/bin/flink run /home/tanghc/IdeaProjects/firstcode/target/firstcode-1.0-SNAPSHOT-jar-with-dependencies.jar
# Dynamically specify
./FLINK_HOME/bin/flink run -c hctang.tech.socketWindowwordCountScala /home/tanghc/IdeaProjects/firstcode/target/firstcode-1.0-SNAPSHOT-jar-with-dependencies.jar
Look at the output
tail -f FLINK_HOME/log/flink-tanghc-taskexecutor-0-tanghc-X550JX.out
边栏推荐
- Pycharm导入已有的本地安装包
- 项目优化个人感悟
- [sword finger offer] interview question 51: reverse pairs in the array - merge sort
- Wechat applet personal number opens traffic master
- juc包下常用工具类
- keil 采用 makefile 实现编译
- The new JMeter function assistant is not under the options menu - in the toolbar
- Taking advantage of 5g Dongfeng, does MediaTek want to fight the high-end market again?
- [sword finger offer] interview question 52: the first common node of two linked lists - stack, hash table, double pointer
- Scratch crawler framework
猜你喜欢

Coding skills - Global exception capture & unified return body & Business exception

Flask connects to existing tables in MySQL database

时间序列-ARIMA模型

Leetcode 226 翻转二叉树(递归)

解决MT7620不断循环uboot(LZMA ERROR 1 - must RESET board to recover)

编码技巧——全局异常捕获&统一的返回体&业务异常

文本截取图片(哪吒之魔童降世壁纸)

Pycharm导入已有的本地安装包

无线网络分析有关的安全软件(aircrack-ng)

Axure 安装图标字体元件库
随机推荐
Brief description of tenant and multi tenant concepts in cloud management platform
Understand │ what is cross domain? How to solve cross domain problems?
Mapreduce实例(三):数据去重
ARIMA模型选择与残差
Live broadcast software development, customized pop-up effect of tools
编码技巧——全局异常捕获&统一的返回体&业务异常
JWT简介
Openwrt compilation driver module (write code at any position outside the openwrt source code, and compile independently in a modular manner.Ko)
一款功能强大的Web漏洞扫描和验证工具(Vulmap)
[sword finger offer] interview question 56-i: the number of numbers in the array I
JMeter5.3 及以后的版本jmeter函数助手生成的字符在置灰无法复制
[sword finger offer] interview question 51: reverse pairs in the array - merge sort
Hematemesis finishing c some commonly used help classes
Pychart import existing project
: 0xc0000005: an access conflict occurs when writing position 0x01458000 - to be solved
Taking advantage of 5g Dongfeng, does MediaTek want to fight the high-end market again?
Enable shallow and deep copies+
firefox旧版本
微信小程序个人号开通流量主
减小程序rom ram,gcc -ffunction-sections -fdata-sections -Wl,–gc-sections 参数详解