当前位置:网站首页>【Flink】提交jar包到Flink集群并运行
【Flink】提交jar包到Flink集群并运行
2022-07-19 22:37:00 【没有BUG就是最大的BUG】
场景:监听一个文本流端口进行数据的实时计算(字符出现的次数)
一、在liunx中开启一个端口
[[email protected] ~]# nc -lk 7777
二、编写任务代码
public class Test {
public static void main(String[] args) throws Exception {
//创建执行环境
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
//获取程序入参
ParameterTool tool = ParameterTool.fromArgs(args);
String host = tool.get("host");
Integer port = tool.getInt("port");
//读取文本流
DataStreamSource<String> source = env.socketTextStream(host, port);
SingleOutputStreamOperator<Tuple2<String, Integer>> operator = source.flatMap(new FlatMapFunction<String, Tuple2<String, Integer>>() {
@Override
public void flatMap(String s, Collector<Tuple2<String, Integer>> collector) throws Exception {
String[] splits = s.split(" ");
for (String split : splits) {
collector.collect(new Tuple2<>(split, 1));
}
}
}).filter(data -> StringUtils.isNotEmpty(data.f0)).keyBy(data -> data.f0).sum(1);
//打印
operator.print();
//执行
env.execute();
}
}
三、打包并提交jar包
在liunx窗口输入字符,查看flink日志已动态打印字符出现的次数
边栏推荐
- 产品加速推进、管理决策权提升,大众中国将以强劲复苏之势加速奔跑!
- Success factors of software R & D effectiveness measurement
- Flexible array
- Analysis of the market trend in the second half of this bull market? 2021-04-07
- uniapp-picker选择省市区效果demo(整理)
- ECCV 2022 | semantic novelty detection based on relational reasoning
- ARM PWN基础教程
- 226. 翻转二叉树-dfs法
- 132 days From electronics factory assembly line to high paid programmer
- 华泰证券h5开户安全吗?可以开吗?
猜你喜欢
随机推荐
函数入门
【云驻共创】手把手教你系列之鸿蒙设备开发之从0到1联网上云实操
01_教育3
Is it safe to open an online stock account in different places?
There is still a lot of room for innovation in defi, and high-quality projects will appear in the future 2021-04-13
98年的成都小产品,入职国企两年半,薪资突破18k
MySQL lock (I)
深度学习从零构建一个模型的方法
[leetcode daily question - missing numbers]
Do you really understand continuous integration (CI)?
shell 字符串
从富士康大厂流水线,到入职互联网大厂腾讯软件测试岗,我花了2年~
数组常用方法
【云驻共创】华为云助力加速构建企业数据资产和数据治理生产线
Leetcode question set SQL (I)
深度学习——神经网络、ML策略
[cloud native] IVX low code development was introduced into Tencent map and previewed online
MySQL select usage 1
都说软件测试有手就行,但为何仍有这么多劝退的?
Request method ‘POST‘ not supported。 Failed to load resource: net::ERR_ FAILED