1. 程式人生 > >Storm框架:如何實現crontab定時任務

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;
    }
}