如何在Apache Storm拓扑中运行定期任务? [英] How to run periodic tasks in an Apache Storm topology?
问题描述
我有一个Apache Storm拓扑,想偶尔执行一次特定的操作.我不确定如何以一种自然而优雅的方式来解决这个问题.
I have an Apache Storm topology and would like to perform a certain action every once in a while. I'm not sure how to approach this in a way which would be natural and elegant.
使用ScheduledExecutorService
是Bolt
还是Spout
,还是其他?
Should it be a Bolt
or a Spout
using ScheduledExecutorService
, or something else?
推荐答案
Tick元组是不错的选择 https://kitmenke.com/blog/2014/08/04/tick-tuples-within-storm/
Tick tuples are a decent option https://kitmenke.com/blog/2014/08/04/tick-tuples-within-storm/
这是螺栓的基本代码
@Override
public Map<String, Object> getComponentConfiguration() {
// configure how often a tick tuple will be sent to our bolt
Config conf = new Config();
conf.put(Config.TOPOLOGY_TICK_TUPLE_FREQ_SECS, 300);
return conf;
}
然后,您可以使用execute
中的TupleUtils.isTick(tuple)
来检查接收到的元组是否是刻度元组.
Then you can use TupleUtils.isTick(tuple)
in execute
to check whether the received tuple is a tick tuple.
这篇关于如何在Apache Storm拓扑中运行定期任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!