如何在 Apache Storm 拓扑中运行周期性任务? [英] How to run periodic tasks in an Apache Storm topology?

查看:31
本文介绍了如何在 Apache Storm 拓扑中运行周期性任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 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.

它应该是一个 Bolt 还是一个使用 ScheduledExecutorServiceSpout,或者其他什么?

Should it be a Bolt or a Spout using ScheduledExecutorService, or something else?

推荐答案

Tick tuples 是一个不错的选择 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/

这是你的螺栓的基本代码

Here's the essential code for your bolt

@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)来检查接收到的tuple是否是tick tuple.

Then you can use TupleUtils.isTick(tuple) in execute to check whether the received tuple is a tick tuple.

这篇关于如何在 Apache Storm 拓扑中运行周期性任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆