当前位置:网站首页>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
边栏推荐
- C语言实现字节流与十六进制字符串的相互转换
- 判断数据的精确类型
- 逗号操作符你有用过吗?
- 新版jmeter函数助手不在选项菜单下-在工具栏中
- Reduce program ROM ram, GCC -ffunction sections -fdata sections -wl, – detailed explanation of GC sections parameters
- MySQL索引
- Pychart imports the existing local installation package
- Text capture picture (Wallpaper of Nezha's demon child coming to the world)
- Determine the exact type of data
- 一款功能强大的Web漏洞扫描和验证工具(Vulmap)
猜你喜欢

Leetcode 226 flip binary tree (recursive)

Text capture picture (Wallpaper of Nezha's demon child coming to the world)

Axure 安装图标字体元件库

: 0xc0000005: an access conflict occurs when writing position 0x01458000 - to be solved

JSP Foundation

First acquaintance with MySQL database

Mapreduce实例(二):求平均值

The new JMeter function assistant is not under the options menu - in the toolbar

Sword finger offer 51. reverse pairs in the array

webRTC中的coturn服务安装
随机推荐
Understand │ what is cross domain? How to solve cross domain problems?
Busybox login: can't execute'/bin/bash': no such file or directory solution
[sword finger offer] interview question 49: ugly number
Flask connects to existing tables in MySQL database
scrapy爬虫框架
The new JMeter function assistant is not under the options menu - in the toolbar
To meet risc-v challenges? ARM CPU introduces custom instruction function!
These questions~~
leetcode25题:K 个一组翻转链表——链表困难题目详解
Taking advantage of 5g Dongfeng, does MediaTek want to fight the high-end market again?
Openwrt compilation driver module (write code at any position outside the openwrt source code, and compile independently in a modular manner.Ko)
2.2 JMeter基本元件
Hematemesis finishing c some commonly used help classes
ARIMA模型选择与残差
Mapreduce实例(三):数据去重
无线网络分析有关的安全软件(aircrack-ng)
Chapter I Marxist philosophy is a scientific world outlook and methodology
时间序列——使用tsfresh进行分类任务
Web test learning notes 01
使用transform:translate()出现内容模糊问题