-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataStream API.html
1436 lines (762 loc) · 73 KB
/
DataStream API.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML>
<html lang="" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>DataStream API · GitBook</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.3">
<link rel="stylesheet" href="../gitbook/style.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
<link rel="next" href="../ps/handbooks.html" />
<link rel="prev" href="将Flink导入IDE.html" />
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="Type to search" />
</div>
<nav role="navigation">
<ul class="summary">
<li class="chapter " data-level="1.1" data-path="../">
<a href="../">
Introduction
</a>
</li>
<li class="chapter " data-level="1.2" data-path="../ch0/preface.html">
<a href="../ch0/preface.html">
开发环境准备:IDEA常用的插件
</a>
<ul class="articles">
<li class="chapter " data-level="1.2.1" data-path="../ch0/RepSearchPractice.html">
<a href="../ch0/RepSearchPractice.html">
Alibaba Java Coding Guidelines
</a>
</li>
<li class="chapter " data-level="1.2.2" data-path="../ch0/RepTaskBasic.html">
<a href="../ch0/RepTaskBasic.html">
SonarLint
</a>
</li>
<li class="chapter " data-level="1.2.3" data-path="../ch0/RepTaskAdvanced.html">
<a href="../ch0/RepTaskAdvanced.html">
ESLint
</a>
</li>
<li class="chapter " data-level="1.2.4" data-path="../ch0/handbook.html">
<a href="../ch0/handbook.html">
Git Commit Template
</a>
</li>
<li class="chapter " data-level="1.2.5" data-path="../ch0/PlantUML.html">
<a href="../ch0/PlantUML.html">
PlantUML
</a>
</li>
<li class="chapter " data-level="1.2.6" data-path="../ch0/DIagram.html">
<a href="../ch0/DIagram.html">
Diagram
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.3" data-path="../ch1/">
<a href="../ch1/">
Spring Cloud
</a>
<ul class="articles">
<li class="chapter " data-level="1.3.1" data-path="../ch1/RepSearchPractice.md">
<span>
检索实操
</a>
</li>
<li class="chapter " data-level="1.3.2" data-path="../ch1/RepTaskBasic.html">
<a href="../ch1/RepTaskBasic.html">
基础任务
</a>
</li>
<li class="chapter " data-level="1.3.3" data-path="../ch1/RepTaskAdvanced.html">
<a href="../ch1/RepTaskAdvanced.html">
进阶任务
</a>
</li>
<li class="chapter " data-level="1.3.4" data-path="../ch1/handbook.html">
<a href="../ch1/handbook.html">
个人教程
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.4" data-path="../ch2/">
<a href="../ch2/">
第二讲:Linux基本命令使用
</a>
<ul class="articles">
<li class="chapter " data-level="1.4.1" data-path="../ch2/top.html">
<a href="../ch2/top.html">
Top命令详解
</a>
</li>
<li class="chapter " data-level="1.4.2" data-path="../ch2/RepTaskBasic.html">
<a href="../ch2/RepTaskBasic.html">
基础任务
</a>
</li>
<li class="chapter " data-level="1.4.3" data-path="../ch2/RepTaskAdvanced.html">
<a href="../ch2/RepTaskAdvanced.html">
进阶任务
</a>
</li>
<li class="chapter " data-level="1.4.4" data-path="../ch2/handbook.html">
<a href="../ch2/handbook.html">
个人教程
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.5" data-path="../ch3/">
<a href="../ch3/">
第三讲:相关工具入门
</a>
<ul class="articles">
<li class="chapter " data-level="1.5.1" data-path="../ch3/UML.html">
<a href="../ch3/UML.html">
UML类图入门
</a>
</li>
<li class="chapter " data-level="1.5.2" data-path="../ch3/scoop.html">
<a href="../ch3/scoop.html">
SCOOP
</a>
</li>
<li class="chapter " data-level="1.5.3" data-path="../ch3/brewhome.html">
<a href="../ch3/brewhome.html">
BrewHome
</a>
</li>
<li class="chapter " data-level="1.5.4" data-path="../ch3/handbook.html">
<a href="../ch3/handbook.html">
个人教程
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.6" data-path="../ch4/">
<a href="../ch4/">
第四讲:Spring Security Oauth2
</a>
<ul class="articles">
<li class="chapter " data-level="1.6.1" data-path="../ch4/oauth2.html">
<a href="../ch4/oauth2.html">
理解OAuth 2.0
</a>
</li>
<li class="chapter " data-level="1.6.2" data-path="../ch4/RepTaskBasic.html">
<a href="../ch4/RepTaskBasic.html">
Spring Security Oauth2(一)
</a>
</li>
<li class="chapter " data-level="1.6.3" data-path="../ch4/RepTaskAdvanced.html">
<a href="../ch4/RepTaskAdvanced.html">
Spring Security Oauth2(二)
</a>
</li>
<li class="chapter " data-level="1.6.4" data-path="../ch4/handbook.html">
<a href="../ch4/handbook.html">
Spring Security Oauth2(三)
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.7" data-path="../ch5/">
<a href="../ch5/">
第五讲:中台
</a>
<ul class="articles">
<li class="chapter " data-level="1.7.1" data-path="../ch5/MiddlePlatform.html">
<a href="../ch5/MiddlePlatform.html">
中台的概念与理解
</a>
</li>
<li class="chapter " data-level="1.7.2" data-path="../ch5/RepTaskBasic.html">
<a href="../ch5/RepTaskBasic.html">
基础任务
</a>
</li>
<li class="chapter " data-level="1.7.3" data-path="../ch5/RepTaskAdvanced.html">
<a href="../ch5/RepTaskAdvanced.html">
进阶任务
</a>
</li>
<li class="chapter " data-level="1.7.4" data-path="../ch5/handbook.html">
<a href="../ch5/handbook.html">
个人教程
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.8" data-path="../ch6/">
<a href="../ch6/">
第六讲:单元测试
</a>
<ul class="articles">
<li class="chapter " data-level="1.8.1" data-path="../ch6/junit.html">
<a href="../ch6/junit.html">
mockito简单实用
</a>
</li>
<li class="chapter " data-level="1.8.2" data-path="../ch6/RepTaskBasic.html">
<a href="../ch6/RepTaskBasic.html">
基础任务
</a>
</li>
<li class="chapter " data-level="1.8.3" data-path="../ch6/AssertJ.html">
<a href="../ch6/AssertJ.html">
AssertJ断言机制记录
</a>
</li>
<li class="chapter " data-level="1.8.4" data-path="../ch6/handbook.html">
<a href="../ch6/handbook.html">
个人教程
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.9" data-path="../ch7/README.md">
<span>
第七讲:缓存
</a>
<ul class="articles">
<li class="chapter " data-level="1.9.1" data-path="../ch7/junit.md">
<span>
mockito简单实用
</a>
</li>
<li class="chapter " data-level="1.9.2" data-path="../ch7/RepTaskBasic.md">
<span>
基础任务
</a>
</li>
<li class="chapter " data-level="1.9.3" data-path="../ch7/AssertJ.md">
<span>
AssertJ断言机制记录
</a>
</li>
<li class="chapter " data-level="1.9.4" data-path="../ch7/handbook.md">
<span>
个人教程
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.10" data-path="../ch8/">
<a href="../ch8/">
辅助
</a>
<ul class="articles">
<li class="chapter " data-level="1.10.1" data-path="../ch8/gitbook.html">
<a href="../ch8/gitbook.html">
gitbook
</a>
</li>
<li class="chapter " data-level="1.10.2" data-path="../ch8/github.html">
<a href="../ch8/github.html">
github
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.11" data-path="README.md">
<span>
第八讲:apache Flink
</a>
<ul class="articles">
<li class="chapter " data-level="1.11.1" data-path="info.html">
<a href="info.html">
介绍
</a>
</li>
<li class="chapter " data-level="1.11.2" data-path="user.html">
<a href="user.html">
应用场景
</a>
</li>
<li class="chapter " data-level="1.11.3" data-path="install.html">
<a href="install.html">
部署
</a>
</li>
<li class="chapter " data-level="1.11.4" data-path="Flink概述与源码研读准备.html">
<a href="Flink概述与源码研读准备.html">
Flink概述与源码研读准备
</a>
</li>
<li class="chapter " data-level="1.11.5" data-path="从源码构建Flink.html">
<a href="从源码构建Flink.html">
从源码构建Flink
</a>
</li>
<li class="chapter " data-level="1.11.6" data-path="将Flink导入IDE.html">
<a href="将Flink导入IDE.html">
将Flink导入IDE
</a>
</li>
<li class="chapter active" data-level="1.11.7" data-path="DataStream API.html">
<a href="DataStream API.html">
DataStream API
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.12" data-path="../ps/handbooks.html">
<a href="../ps/handbooks.html">
备注
</a>
</li>
<li class="chapter " data-level="1.13" data-path="../ps/ref.html">
<a href="../ps/ref.html">
参考文献
</a>
</li>
<li class="chapter " data-level="1.14" data-path="../ps/thanks.html">
<a href="../ps/thanks.html">
致谢
</a>
</li>
<li class="chapter " data-level="1.15" data-path="../no_end/postscript.html">
<a href="../no_end/postscript.html">
后记
</a>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
Published with GitBook
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href=".." >DataStream API</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<h1 id="datastream-api">DataStream API</h1>
<p>Apache Flink 提供了 DataStream API 来实现稳定可靠的、有状态的流处理应用程序。 Flink 支持对状态和时间的细粒度控制,以此来实现复杂的事件驱动数据处理系统。 这个入门指导手册讲述了如何通过 Flink DataStream API 来实现一个有状态流处理程序。</p>
<ul>
<li><a href="https://ci.apache.org/projects/flink/flink-docs-release-1.10/zh/getting-started/walkthroughs/datastream_api.html#你要搭建一个什么系统" target="_blank">你要搭建一个什么系统</a></li>
<li><a href="https://ci.apache.org/projects/flink/flink-docs-release-1.10/zh/getting-started/walkthroughs/datastream_api.html#准备条件" target="_blank">准备条件</a></li>
<li><a href="https://ci.apache.org/projects/flink/flink-docs-release-1.10/zh/getting-started/walkthroughs/datastream_api.html#困难求助" target="_blank">困难求助</a></li>
<li><a href="https://ci.apache.org/projects/flink/flink-docs-release-1.10/zh/getting-started/walkthroughs/datastream_api.html#怎样跟着教程练习" target="_blank">怎样跟着教程练习</a></li>
<li><a href="https://ci.apache.org/projects/flink/flink-docs-release-1.10/zh/getting-started/walkthroughs/datastream_api.html#代码分析" target="_blank">代码分析</a></li>
<li><a href="https://ci.apache.org/projects/flink/flink-docs-release-1.10/zh/getting-started/walkthroughs/datastream_api.html#实现一个真正的应用程序" target="_blank">实现一个真正的应用程序</a></li>
<li><a href="https://ci.apache.org/projects/flink/flink-docs-release-1.10/zh/getting-started/walkthroughs/datastream_api.html#欺诈检测器-v2状态--时间--️" target="_blank">欺诈检测器 v2:状态 + 时间 = ❤️</a></li>
<li>完整的程序<ul>
<li><a href="https://ci.apache.org/projects/flink/flink-docs-release-1.10/zh/getting-started/walkthroughs/datastream_api.html#期望的结果" target="_blank">期望的结果</a></li>
</ul>
</li>
</ul>
<h2 id="你要搭建一个什么系统">你要搭建一个什么系统</h2>
<p>在当今数字时代,信用卡欺诈行为越来越被重视。 罪犯可以通过诈骗或者入侵安全级别较低系统来盗窃信用卡卡号。 用盗得的信用卡进行很小额度的例如一美元或者更小额度的消费进行测试。 如果测试消费成功,那么他们就会用这个信用卡进行大笔消费,来购买一些他们希望得到的,或者可以倒卖的财物。</p>
<p>在这个教程中,你将会建立一个针对可疑信用卡交易行为的反欺诈检测系统。 通过使用一组简单的规则,你将了解到 Flink 如何为我们实现复杂业务逻辑并实时执行。</p>
<h2 id="准备条件">准备条件</h2>
<p>这个代码练习假定你对 Java 或 Scala 有一定的了解,当然,如果你之前使用的是其他开发语言,你也应该能够跟随本教程进行学习。</p>
<h2 id="困难求助">困难求助</h2>
<p>如果遇到困难,可以参考 <a href="https://flink.apache.org/zh/gettinghelp.html" target="_blank">社区支持资源</a>。 当然也可以在邮件列表提问,Flink 的 <a href="https://flink.apache.org/zh/community.html#mailing-lists" target="_blank">用户邮件列表</a> 一直被评为所有Apache项目中最活跃的一个,这也是快速获得帮助的好方法。</p>
<h2 id="怎样跟着教程练习">怎样跟着教程练习</h2>
<p>首先,你需要在你的电脑上准备以下环境:</p>
<ul>
<li>Java 8 or 11</li>
<li>Maven</li>
</ul>
<p>一个准备好的 Flink Maven Archetype 能够快速创建一个包含了必要依赖的 Flink 程序骨架,基于此,你可以把精力集中在编写业务逻辑上即可。 这些已包含的依赖包括 <code>flink-streaming-java</code>、<code>flink-walkthrough-common</code> 等,他们分别是 Flink 应用程序的核心依赖项和这个代码练习需要的数据生成器,当然还包括其他本代码练习所依赖的类。</p>
<p><strong>说明:</strong> 为简洁起见,本练习中的代码块中可能不包含完整的类路径。完整的类路径可以在文档底部 <a href="https://ci.apache.org/projects/flink/flink-docs-release-1.10/zh/getting-started/walkthroughs/datastream_api.html#完整的程序" target="_blank">链接</a> 中找到。</p>
<ul>
<li><a href="https://ci.apache.org/projects/flink/flink-docs-release-1.10/zh/getting-started/walkthroughs/datastream_api.html#tab_java_0" target="_blank"><strong>Java</strong></a></li>
<li><a href="https://ci.apache.org/projects/flink/flink-docs-release-1.10/zh/getting-started/walkthroughs/datastream_api.html#tab_scala_0" target="_blank"><strong>Scala</strong></a></li>
</ul>
<pre><code>$ mvn archetype:generate \
-DarchetypeGroupId=org.apache.flink \
-DarchetypeArtifactId=flink-walkthrough-datastream-java \
-DarchetypeVersion=1.10.0 \
-DgroupId=frauddetection \
-DartifactId=frauddetection \
-Dversion=0.1 \
-Dpackage=spendreport \
-DinteractiveMode=false
</code></pre><p>你可以根据自己的情况修改 <code>groupId</code>、 <code>artifactId</code> 和 <code>package</code>。通过这三个参数, Maven 将会创建一个名为 <code>frauddetection</code> 的文件夹,包含了所有依赖的整个工程项目将会位于该文件夹下。 将工程目录导入到你的开发环境之后,你可以找到 <code>FraudDetectionJob.java</code> (或 <code>FraudDetectionJob.scala</code>) 代码文件,文件中的代码如下所示。你可以在 IDE 中直接运行这个文件。 同时,你可以试着在数据流中设置一些断点或者以 DEBUG 模式来运行程序,体验 Flink 是如何运行的。</p>
<ul>
<li><a href="https://ci.apache.org/projects/flink/flink-docs-release-1.10/zh/getting-started/walkthroughs/datastream_api.html#tab_java_1" target="_blank"><strong>Java</strong></a></li>
<li><a href="https://ci.apache.org/projects/flink/flink-docs-release-1.10/zh/getting-started/walkthroughs/datastream_api.html#tab_scala_1" target="_blank"><strong>Scala</strong></a></li>
</ul>
<h4 id="frauddetectionjobjava">FraudDetectionJob.java</h4>
<pre><code>package spendreport;