我的输入流
type=1, time=10, start=123, other params
type=2, time=11, start=123, other params
type=2, time=12, start=123, other params
type=1, time=13, start=235, other params
type=2, time=14, start=123, other params
type=2, time=15, start=235, other params
type=2, time=16, start=235, other params
type=1, time=17, start=456, other params
...
我想创建一个以type = 1事件开头的窗口。之后,我会连续不断地进行type = 2事件,直到key start = 123停止。
Type = 1事件类似于开始事件,type = 2事件类似于ping事件,以指示生产者仍然存在。我将它们放在两个单独的主题中。
我有一个想法,要创建一个自定义会话窗口,该窗口在type = 1事件发生时启动,该窗口一直打开,直到距上次type = 2事件超过3分钟为止。
stream
.keyBy(start)
.window(CustomWindow())
.trigger(CustomTrigger())
...
但是,我不知道如何创建仅在收到事件类型= 1时才启动的自定义窗口。我读了有关Trigger的文章,它是关于window函数何时触发的,而不是有关何时创建Window的。
预期结果:
type=event-end, start=123, duration=3 (because there are 3 type=2 log for 123)
-> this fires at time=17 because last ping event is at time=14, there is a gap of 3.
type=event-end, start=235, duration=2 (because there are 3 type=2 log for 123)
-> this fires at time=19 because last ping event is at time=16, there is a gap of 3 and if there is no more ping after time=16.
如何在Flink中实现此自定义窗口?