Flink初级编程实践

该博客详细介绍了如何在Ubuntu上使用IntelliJ IDEA开发Flink WordCount程序。从实验目的、平台配置到具体步骤,包括编写Java代码、配置pom.xml、打包JAR文件,以及如何在Flink环境中运行和调试程序。通过实例展示了Flink实时处理数据流和计算词频的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


实验7

Flink初级编程实践

1.实验目的

(1)通过实验掌握基本的Flink编程方法。

(2)掌握用IntelliJ IDEA工具编写Flink程序的方法。

2.实验平台

(1)Ubuntu18.04(或Ubuntu16.04)。

(2)IntelliJ IDEA。

(3)Flink1.9.1。

3.实验步骤

(1)使用IntelliJ IDEA工具开发WordCount程序

在Linux系统中安装IntelliJ IDEA,然后使用IntelliJ IDEA工具开发WordCount程序,并打包成JAR文件,提交到Flink中运行。

#启动Flink

cd /usr/local/flink

./bin/start-cluster.sh

#启动IntelliJ IDEA

cd /usr/local/idea

./bin/idea.sh

在idea中创建FlinkTest项目,在Java包中编写WordCountData.java,WordCountTokenizer.java,WordCount.java

首先弄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>org.example</groupId>
    <artifactId>FinkWordCount</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.apache.flink/flink-java -->
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-java</artifactId>
            <version>1.9.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.flink/flink-streaming-java -->
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-streaming-java_2.12</artifactId>
            <version>1.9.1</version>
            <scope>provided</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.flink/flink-clients -->
        <dependency>
            <groupId>org.apache.flink</groupId&g
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值