我正在使用 Storm 实现的滑动窗口:
这是我的拓扑:
public static void main(String[] args) throws Exception {
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("rabbitSpout", new RabbitMQSpout());
builder.setBolt("filterBolt", new FilteringBolt()).shuffleGrouping("rabbitSpout");
builder.setBolt("HourStatisticsBolt", new SlidingWindowStatisticsBolt()
.withWindow(new BaseWindowedBolt.Duration(60, TimeUnit.MINUTES),
new BaseWindowedBolt.Duration(10, TimeUnit.SECONDS))
.withTimestampField("timestamp")).shuffleGrouping("filterBolt");
在我的 SlidingWindowStatisticsBolt 的执行方法中,我想获取窗口开始或结束的时间戳。在我的 bolt 中,如何获得窗口长度和滑动持续时间?
最佳答案
由于您使用的是事件时间 (withTimestampField
),因此窗口是根据周期性水印计算的。现在,窗口开始/结束时间未在 TupleWindow 中公开。
在 Storm 的最新主分支中,TupleWindow有一个 getTimestamp 方法,它返回窗口结束时间戳,适用于基于处理和事件时间的窗口。这将在 Storm 的 future 版本(2.0 版本)中提供。如果您希望向后移植并在下一个 1.x 版本中提供此功能,您可以提交 JIRA here
关于java - 如何在滑动窗口中获取当前窗口时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43159507/