Storm框架:如何實現crontab定時任務
阿新 • • 發佈:2018-11-02
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; } }