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

@Override
public Map<String,  > 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;
    }
}
收藏 打印