首页   快速返回

flink快速入门
文章分类 flink
发布时间 2018-11-13 修改时间 2018-11-13
https://ci.apache.org/projects/flink/flink-docs-release-1.6/quickstart/setup_quickstart.html


flink 1.6.2

/Users/dugang/soft/flink/flink-1.6.2
启动一个本地实例
./bin/start-cluster.sh 
web控制台 
http://localhost:8081

例子代码 SocketWindowWordCount
从socket中读取数据 统计单词个数


https://github.com/apache/flink/blob/master/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/socket/SocketWindowWordCount.java

使用netcat 启动 socket 服务 ,从控制台读取输入
nc -l 9000 
提交 flink 任务
./bin/flink run examples/streaming/SocketWindowWordCount.jar --port 9000

It will read text from a socket and once every 5 seconds print the number of occurrences of each distinct word during the previous 5 seconds, 
i.e. a tumbling window of processing time, as long as words are floating in.

从socket读取数据,每隔5秒聚合统计单词个数

查看flink 相关的进程
ps aux|grep flink


/usr/bin/java -Xms1024m -Xmx1024m -Dlog.file=/Users/dugang/soft/flink/flink-1.6.2/log/flink-dugang-standalonesession-0-localhost.log -Dlog4j.configuration=file:/Users/dugang/soft/flink/flink-1.6.2/conf/log4j.properties -Dlogback.configurationFile=file:/Users/dugang/soft/flink/flink-1.6.2/conf/logback.xml -classpath /Users/dugang/soft/flink/flink-1.6.2/lib/flink-python_2.11-1.6.2.jar:/Users/dugang/soft/flink/flink-1.6.2/lib/log4j-1.2.17.jar:/Users/dugang/soft/flink/flink-1.6.2/lib/slf4j-log4j12-1.7.7.jar:/Users/dugang/soft/flink/flink-1.6.2/lib/flink-dist_2.11-1.6.2.jar::: org.apache.flink.runtime.entrypoint.StandaloneSessionClusterEntrypoint --configDir /Users/dugang/soft/flink/flink-1.6.2/conf --executionMode cluster
/usr/bin/java -XX:+UseG1GC -Xms922M -Xmx922M -XX:MaxDirectMemorySize=8388607T -Dlog.file=/Users/dugang/soft/flink/flink-1.6.2/log/flink-dugang-taskexecutor-0-localhost.log -Dlog4j.configuration=file:/Users/dugang/soft/flink/flink-1.6.2/conf/log4j.properties -Dlogback.configurationFile=file:/Users/dugang/soft/flink/flink-1.6.2/conf/logback.xml -classpath /Users/dugang/soft/flink/flink-1.6.2/lib/flink-python_2.11-1.6.2.jar:/Users/dugang/soft/flink/flink-1.6.2/lib/log4j-1.2.17.jar:/Users/dugang/soft/flink/flink-1.6.2/lib/slf4j-log4j12-1.7.7.jar:/Users/dugang/soft/flink/flink-1.6.2/lib/flink-dist_2.11-1.6.2.jar::: org.apache.flink.runtime.taskexecutor.TaskManagerRunner --configDir /Users/dugang/soft/flink/flink-1.6.2/conf
/usr/bin/java -Dlog.file=/Users/dugang/soft/flink/flink-1.6.2/log/flink-dugang-client-localhost.log -Dlog4j.configuration=file:/Users/dugang/soft/flink/flink-1.6.2/conf/log4j-cli.properties -Dlogback.configurationFile=file:/Users/dugang/soft/flink/flink-1.6.2/conf/logback.xml -classpath /Users/dugang/soft/flink/flink-1.6.2/lib/flink-python_2.11-1.6.2.jar:/Users/dugang/soft/flink/flink-1.6.2/lib/log4j-1.2.17.jar:/Users/dugang/soft/flink/flink-1.6.2/lib/slf4j-log4j12-1.7.7.jar:/Users/dugang/soft/flink/flink-1.6.2/lib/flink-dist_2.11-1.6.2.jar::: org.apache.flink.client.cli.CliFrontend run /Users/dugang/tmp/x/flinkdemo-1.0.0.jar --port 9000

org.apache.flink.runtime.entrypoint.StandaloneSessionClusterEntrypoint
org.apache.flink.runtime.taskexecutor.TaskManagerRunner
org.apache.flink.client.cli.CliFrontend


单独建立一个例子工程 需要依赖
org.apache.flink.flink-java 1.6.2
org.apache.flink.flink-streaming-java_2.11 1.6.2
例子工程见
https://gitee.com/dyyx/hellocode/tree/master/project/flink

打成jar包  META-INF/MANIFEST.MF 需要加上 program-class=flinkdemo.SocketWindowWordCount
pom.xml   build.plugins.plugin.configuration.archive.manifestEntries  增加相应配置

上一篇     下一篇
Java线程状态中BLOCKED和WAITING的区别

Java运行时数据区

面试技巧之STAR法则

flink web控制台介绍

Netty和Akka的区别

Spark SQL 进化史