Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
武汉红喜
whatsmars
提交
2b398d53
W
whatsmars
项目概览
武汉红喜
/
whatsmars
通知
3
Star
0
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
whatsmars
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
2b398d53
编写于
11月 01, 2019
作者:
武汉红喜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
flink
上级
293fb1c3
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
230 addition
and
1 deletion
+230
-1
README.md
README.md
+2
-1
pom.xml
pom.xml
+1
-0
whatsmars-flink/pom.xml
whatsmars-flink/pom.xml
+73
-0
whatsmars-flink/src/main/java/org/hongxi/whatsmars/flink/streaming/WordCount.java
.../java/org/hongxi/whatsmars/flink/streaming/WordCount.java
+102
-0
whatsmars-flink/src/main/java/org/hongxi/whatsmars/flink/streaming/util/WordCountData.java
.../hongxi/whatsmars/flink/streaming/util/WordCountData.java
+47
-0
whatsmars-flink/src/main/resources/log4j.properties
whatsmars-flink/src/main/resources/log4j.properties
+5
-0
未找到文件。
README.md
浏览文件 @
2b398d53
...
...
@@ -18,6 +18,7 @@ whatsmars-common | Utils公共模块 / Java SE demo
whatsmars-dubbo | 高性能分布式RPC框架
whatsmars-elasticjob | 分布式调度框架
whatsmars-elasticsearch | Elasticsearch
whatsmars-flink | 分布式流处理框架
whatsmars-mq | 消息中间件RocketMQ,Kafka等
whatsmars-redis | Redis客户端简单封装
whatsmars-rpc | Transporter & Codec & Serialization
...
...
@@ -26,7 +27,7 @@ whatsmars-spring | Spring Framework
whatsmars-spring-boot | Spring Boot 实战
whatsmars-spring-boot-samples | Spring Boot Samples
whatsmars-spring-cloud | Spring Cloud 微服务生态
whatsmars-storm | 分布式
实时计算系统
whatsmars-storm | 分布式
流处理框架
whatsmars-zk | zookeeper remoting 封装
### Rocket Stack
...
...
pom.xml
浏览文件 @
2b398d53
...
...
@@ -31,6 +31,7 @@
<module>
whatsmars-elasticsearch
</module>
<module>
whatsmars-zk
</module>
<module>
whatsmars-storm
</module>
<module>
whatsmars-flink
</module>
</modules>
<!--这里的properties会覆盖父pom里的重名的配置-->
...
...
whatsmars-flink/pom.xml
0 → 100644
浏览文件 @
2b398d53
<?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"
>
<parent>
<artifactId>
whatsmars-parent
</artifactId>
<groupId>
org.hongxi
</groupId>
<version>
Rocket.S7
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
whatsmars-flink
</artifactId>
<properties>
<flink.version>
1.9.1
</flink.version>
<scala.binary.version>
2.11
</scala.binary.version>
</properties>
<dependencies>
<!-- Apache Flink dependencies -->
<!-- These dependencies are provided, because they should not be packaged into the JAR file. -->
<dependency>
<groupId>
org.apache.flink
</groupId>
<artifactId>
flink-java
</artifactId>
<version>
${flink.version}
</version>
<!-- <scope>provided</scope>-->
</dependency>
<dependency>
<groupId>
org.apache.flink
</groupId>
<artifactId>
flink-streaming-java_${scala.binary.version}
</artifactId>
<version>
${flink.version}
</version>
<!-- <scope>provided</scope>-->
</dependency>
<!-- Add connector dependencies here. They must be in the default scope (compile). -->
<!-- Example:
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-connector-kafka-0.10_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
</dependency>
-->
<!-- Add logging framework, to produce console output when running in the IDE. -->
<!-- These dependencies are excluded from the application JAR by default. -->
<dependency>
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-log4j12
</artifactId>
</dependency>
<dependency>
<groupId>
log4j
</groupId>
<artifactId>
log4j
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.flink
</groupId>
<artifactId>
flink-test-utils_${scala.binary.version}
</artifactId>
<version>
${flink.version}
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.apache.flink
</groupId>
<artifactId>
flink-streaming-java_${scala.binary.version}
</artifactId>
<version>
${flink.version}
</version>
<!-- <scope>test</scope>-->
<type>
test-jar
</type>
</dependency>
</dependencies>
</project>
\ No newline at end of file
whatsmars-flink/src/main/java/org/hongxi/whatsmars/flink/streaming/WordCount.java
0 → 100644
浏览文件 @
2b398d53
package
org.hongxi.whatsmars.flink.streaming
;
import
org.apache.flink.api.common.functions.FlatMapFunction
;
import
org.apache.flink.api.java.tuple.Tuple2
;
import
org.apache.flink.api.java.utils.ParameterTool
;
import
org.apache.flink.streaming.api.datastream.DataStream
;
import
org.apache.flink.streaming.api.environment.StreamExecutionEnvironment
;
import
org.apache.flink.util.Collector
;
import
org.hongxi.whatsmars.flink.streaming.util.WordCountData
;
/**
* Implements the "WordCount" program that computes a simple word occurrence
* histogram over text files in a streaming fashion.
*
* <p>The input is a plain text file with lines separated by newline characters.
*
* <p>Usage: <code>WordCount --input <path> --output <path></code><br>
* If no parameters are provided, the program is run with default data from
* {@link WordCountData}.
*
* <p>This example shows how to:
* <ul>
* <li>write a simple Flink Streaming program,
* <li>use tuple data types,
* <li>write and use user-defined functions.
* </ul>
*/
public
class
WordCount
{
// *************************************************************************
// PROGRAM
// *************************************************************************
public
static
void
main
(
String
[]
args
)
throws
Exception
{
// Checking input parameters
final
ParameterTool
params
=
ParameterTool
.
fromArgs
(
args
);
// set up the execution environment
final
StreamExecutionEnvironment
env
=
StreamExecutionEnvironment
.
getExecutionEnvironment
();
// make parameters available in the web interface
env
.
getConfig
().
setGlobalJobParameters
(
params
);
// get input data
DataStream
<
String
>
text
;
if
(
params
.
has
(
"input"
))
{
// read the text file from given input path
text
=
env
.
readTextFile
(
params
.
get
(
"input"
));
}
else
{
System
.
out
.
println
(
"Executing WordCount example with default input data set."
);
System
.
out
.
println
(
"Use --input to specify file input."
);
// get default test text data
text
=
env
.
fromElements
(
WordCountData
.
WORDS
);
}
DataStream
<
Tuple2
<
String
,
Integer
>>
counts
=
// split up the lines in pairs (2-tuples) containing: (word,1)
text
.
flatMap
(
new
Tokenizer
())
// group by the tuple field "0" and sum up tuple field "1"
.
keyBy
(
0
).
sum
(
1
);
// emit result
if
(
params
.
has
(
"output"
))
{
counts
.
writeAsText
(
params
.
get
(
"output"
));
}
else
{
System
.
out
.
println
(
"Printing result to stdout. Use --output to specify output path."
);
counts
.
print
();
}
// execute program
env
.
execute
(
"Streaming WordCount"
);
}
// *************************************************************************
// USER FUNCTIONS
// *************************************************************************
/**
* Implements the string tokenizer that splits sentences into words as a
* user-defined FlatMapFunction. The function takes a line (String) and
* splits it into multiple pairs in the form of "(word,1)" ({@code Tuple2<String,
* Integer>}).
*/
public
static
final
class
Tokenizer
implements
FlatMapFunction
<
String
,
Tuple2
<
String
,
Integer
>>
{
@Override
public
void
flatMap
(
String
value
,
Collector
<
Tuple2
<
String
,
Integer
>>
out
)
{
// normalize and split the line
String
[]
tokens
=
value
.
toLowerCase
().
split
(
"\\W+"
);
// emit the pairs
for
(
String
token
:
tokens
)
{
if
(
token
.
length
()
>
0
)
{
out
.
collect
(
new
Tuple2
<>(
token
,
1
));
}
}
}
}
}
\ No newline at end of file
whatsmars-flink/src/main/java/org/hongxi/whatsmars/flink/streaming/util/WordCountData.java
0 → 100644
浏览文件 @
2b398d53
package
org.hongxi.whatsmars.flink.streaming.util
;
/**
* Provides the default data sets used for the WordCount example program.
* The default data sets are used, if no parameters are given to the program.
*
*/
public
class
WordCountData
{
public
static
final
String
[]
WORDS
=
new
String
[]
{
"To be, or not to be,--that is the question:--"
,
"Whether 'tis nobler in the mind to suffer"
,
"The slings and arrows of outrageous fortune"
,
"Or to take arms against a sea of troubles,"
,
"And by opposing end them?--To die,--to sleep,--"
,
"No more; and by a sleep to say we end"
,
"The heartache, and the thousand natural shocks"
,
"That flesh is heir to,--'tis a consummation"
,
"Devoutly to be wish'd. To die,--to sleep;--"
,
"To sleep! perchance to dream:--ay, there's the rub;"
,
"For in that sleep of death what dreams may come,"
,
"When we have shuffled off this mortal coil,"
,
"Must give us pause: there's the respect"
,
"That makes calamity of so long life;"
,
"For who would bear the whips and scorns of time,"
,
"The oppressor's wrong, the proud man's contumely,"
,
"The pangs of despis'd love, the law's delay,"
,
"The insolence of office, and the spurns"
,
"That patient merit of the unworthy takes,"
,
"When he himself might his quietus make"
,
"With a bare bodkin? who would these fardels bear,"
,
"To grunt and sweat under a weary life,"
,
"But that the dread of something after death,--"
,
"The undiscover'd country, from whose bourn"
,
"No traveller returns,--puzzles the will,"
,
"And makes us rather bear those ills we have"
,
"Than fly to others that we know not of?"
,
"Thus conscience does make cowards of us all;"
,
"And thus the native hue of resolution"
,
"Is sicklied o'er with the pale cast of thought;"
,
"And enterprises of great pith and moment,"
,
"With this regard, their currents turn awry,"
,
"And lose the name of action.--Soft you now!"
,
"The fair Ophelia!--Nymph, in thy orisons"
,
"Be all my sins remember'd."
};
}
\ No newline at end of file
whatsmars-flink/src/main/resources/log4j.properties
0 → 100644
浏览文件 @
2b398d53
log4j.rootLogger
=
INFO, console
log4j.appender.console
=
org.apache.log4j.ConsoleAppender
log4j.appender.console.layout
=
org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern
=
%d{HH:mm:ss,SSS} %-5p %-60c %x - %m%n
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录