如何解决Hazelcast Jet 是否允许从rollingAggregate 查询累加器值?
下面的最小工作示例展示了一些(简化的)处理,其中:
- 每个事件都单独处理(无窗口),
- 每个事件都属于某个组,
- 每个事件更新一个组状态,然后用于生成一些输出值。
public class RollingExample {
public static void main(String[] args) {
JetInstance jet = Jet.newJetInstance();
Pipeline p = Pipeline.create();
p.readFrom(TestSources.itemStream(10))
.withoutTimestamps()
.groupingKey(event -> event.sequence() % 10) //simulates 10 groups
.rollingAggregate(AggregateOperation
.withCreate(DoubleAccumulator::new) //group state simulated by a single double value
.andAccumulate((DoubleAccumulator acc,SimpleEvent event) -> acc.accumulate(event.sequence())) //update group state with given event
.andCombine(DoubleAccumulator::combine)
.andDeduct(DoubleAccumulator::deduct)
.andExportFinish(DoubleAccumulator::export))
.map(x -> x.getKey() + " -> " + x.getValue()) //map group state to some output value
.writeTo(Sinks.logger());
jet.newJob(p).join();
}
}
鉴于上面的例子,是否可以从外部查询单个组的状态,例如使用 Hazelcast 客户端? “查询”是指以编程方式获取给定组的累加器的当前值。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。