如何在Flink流中的空窗口上执行功能?
我编写了一个Flink程序,该程序从简单的kafka流计算每个键控窗口的事件数.我的作品很棒,快速且准确的.当源停止时,我想在每个窗口上将 0
作为计算的结果,但不发送任何结果.该功能只是不执行.我认为这是由于Flink的惰性操作行为所致.
I wrote a Flink program that calculates the number of events per keyed window from a simple kafka stream. I works great, fast & accurate. When the source stops, I would like to have 0
as result of the calculation on each window, but no result is sent. The function just does not execute. I assume this is because of the lazy operation behavior of Flink.
有什么建议吗?
我遇到了同样的情况.一种解决方法是填补数据库中的漏洞.
I encountered the same situation. Filling the holes in your database with another process is a solution.
但是,我发现将您的主流与自定义期刊来源合并起来会更容易,该期刊来源会发出假人,其唯一作用是触发Windows创建.这样做时,必须确保在计算中忽略了虚拟变量.
However, I found it easier to union your main stream with a custom periodical source, that emits dummies, whose only roles are to trigger windows creation. When doing this, you have to make sure that dummies are ignored in computations.
这里是如何编写期刊来源的代码(但是您可能不需要RichParallelSourceFunction,一个SourceFunction就足够了)
Here is how to code a periodical source (however you may not need a RichParallelSourceFunction, a SourceFunction can be enough)