idea flink scala环境搭建记录

参考:flink中idea配置pom.xml_flink项目pom文件_hzp666的博客-CSDN博客

win10安装idea

IntelliJ IDEA 2021.1 (Ultimate Edition)
Build #IU-211.6693.111, built on April 6, 2021
Licensed to IntelliJ IDEA Evaluator
Expiration date: March 29, 2023
Runtime version: 11.0.10+9-b1341.35 amd64
VM: Dynamic Code Evolution 64-Bit Server VM by JetBrains s.r.o.
Windows 10 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 3024M
Cores: 6
Registry: scala.erase.compiler.process.jdk.once=false
Non-Bundled Plugins: org.example.BetterIntelliJ (1.16), org.intellij.scala (2021.1.18)
Kotlin: 211-1.4.32-release-IJ6693.72

java1.8 maven项目

WordCount.scala

package wordcount

import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment

object WordCount {
    /** Main program method */
    def main(args: Array[String]) : Unit = {
        // get the execution environment
        val env:StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment

        import org.apache.flink.streaming.api.scala._
        val text:DataStream[String] = env.socketTextStream("192.168.0.1",9000,'\n')

        // parse the data, group it, window it, and aggregate the counts
        val windowCounts = text.flatMap (_.split("\\s") )
            .map((_,1))
            .keyBy(0)
            .sum(1)

        // print the results with a single thread, rather than in parallel
        windowCounts
            .print()
            .setParallelism(1)

        env.execute("Socket Window WordCount")
    }

    /** Data type for words with count */
    case class WordWithCount(word: String, count: Long)
}

 pom.xml文件

scala 2.12.2 

flink1.14.4

<?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.ddyii.flink</groupId>
    <artifactId>flinkScipt</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.apache.flink/flink-scala -->
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-scala_2.12</artifactId>
            <version>1.14.4</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.flink/flink-streaming-scala -->
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-streaming-scala_2.12</artifactId>
            <version>1.14.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-clients_2.12</artifactId>
            <version>1.14.4</version>
        </dependency>
    </dependencies>

    <build>

        <plugins>

        </plugins>
    </build>
</project>

project structure

自己下载的scala安装包

运行输入

nc -l 9000
hello world hahaha
this is a flink test
who am i
ok stream api ok
this is a flink test
who is this

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值