Storm框架:如何实现crontab定时任务

Storm除了能对消息流进行处理,还能实现crontab定时任务。
只要在bolt中配置TOPOLOGY_TICK_TUPLE_FREQ_SECS项即可实现。

@Override
public Map<String, Object> getComponentConfiguration() {
    Config conf = new Config();
    conf.put(Config.TOPOLOGY_TICK_TUPLE_FREQ_SECS, 60); //每隔60s发送一次tick信号

    return conf;
}

@Override
public void execute(Tuple tuple, BasicOutputCollector basicOutputCollector) {
    if (tuple.getSourceComponent().equals(Constants.SYSTEM_COMPONENT_ID) &&
            tuple.getSourceStreamId().equals(Constants.SYSTEM_TICK_STREAM_ID)) {

        LOGGER.debug("CronBolt Tick at {}", new Date());
        // 执行定时任务操作
    } else {
        return;
    }
}

猜你喜欢

转载自www.cnblogs.com/gouyg/p/java-storm-crontab.html
今日推荐