在我的基于Storm的应用程序中,我需要定期查询oracle表所以我想使用Tick tuple of storm。但它没有给出正确的结果,并且滴答元组不会产生。
我的风暴版本是1.0.1.2.5.3.0-37
我试过如下,
在bolt中添加了getComponentConfiguration方法http://www.michael-noll.com/blog/2013/01/18/implementing-real-time-trending-topics-in-storm/链接,但没有生成tick元组。
所以我更改了代码,并使用拓扑中的Config生成tick元组。我引用https://www.safaribooksonline.com/blog/2014/01/06/multi-threading-storm/链接,但这里我只得到一次tick元组。
下面是我的带螺栓的刻度元组代码,
public class TickTupleBolt implements IRichBolt{
private OutputCollector collector = null;
private static final long serialVersionUID = 1L;
private static final Logger LOG = LoggerFactory.getLogger(TickTupleBolt.class);
public void prepare(Map stormConf, TopologyContext context,OutputCollector collector) {
this.collector = collector;
}
public void execute(Tuple tuple) {
LOG.info("Start of TickTupleBolt.execute");
try {
if (isTickTuple(tuple)) {
//if(tuple.getSourceStreamId().equals("__tick")){
LOG.info("**got tick tuple");
}else{
LOG.info("not got tick tuple");
}
} catch (Exception e) {
LOG.error("Bolt execute error: {}", e);
collector.reportError(e);
}
LOG.info("End of TickTupleBolt.execute");
}
public void cleanup() {
// TODO Auto-generated method stub
}
public void declareOutputFields(OutputFieldsDeclarer declarer) {
// TODO Auto-generated method stub
}
public Map<String, Object> getComponentConfiguration() {
// configure how often a tick tuple will be sent to our bolt
Map<String, Object> conf = new HashMap<String, Object>();
conf.put(Config.TOPOLOGY_TICK_TUPLE_FREQ_SECS, 1);
return conf;
}
protected boolean isTickTuple(Tuple tuple) {
return tuple.getSourceComponent().equals(Constants.SYSTEM_COMPONENT_ID)
&& tuple.getSourceStreamId().equals(Constants.SYSTEM_TICK_STREAM_ID);
}
}
我有一个链接Tick Tuple not functioning in apache storm 0.9.4,但没有答案。
任何身体也可以让我知道,
更新 - 拓扑代码
我的拓扑构建器,
public class Topology {
private static final Logger LOG = LoggerFactory.getLogger(Topology.class);
public static StormTopology buildTopology() {
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("tickspout", new TickTupleSpout());
builder.setBolt("tickbolt", new TickTupleBolt()).shuffleGrouping("tickspout");
return builder.createTopology();
}
public static void main(String[] args) throws AlreadyAliveException, InvalidTopologyException, AuthorizationException {
Config conf = new Config();
//conf.put(Config.TOPOLOGY_TICK_TUPLE_FREQ_SECS, 5);//tried it also
conf.setDebug(true);
//conf.setNumWorkers(2);
StormSubmitter.submitTopology(args[0], conf, buildTopology());
}
}
更新 - 代码
public class TickTupleSpout extends BaseRichSpout{
private static final Logger LOG = LoggerFactory.getLogger(TickTupleSpout.class);
private static final long serialVersionUID = 1L;
private SpoutOutputCollector collector;
public TickTupleSpout() {
}
public void open(Map conf, TopologyContext context,
SpoutOutputCollector collector) {
// TODO Auto-generated method stub
LOG.info("Start of TickTupleSpout.Open");
this.collector = collector;
LOG.info("End of TickTupleSpout.Open");
}
public void nextTuple() {
LOG.info("Start of TickTupleSpout.nextTuple");
this.collector.emit(new Values("0");//just send dummy value
LOG.info("End of TickTupleSpout.nextTuple");
}
public void declareOutputFields(OutputFieldsDeclarer declarer) {
declarer.declare(new Fields("breachdata"));
}
//public Map<String, Object> getComponentConfiguration() {
//Config conf = new Config();
//int tickFrequencyInSeconds = 5;
//conf.put(Config.TOPOLOGY_TICK_TUPLE_FREQ_SECS, tickFrequencyInSeconds);
//return conf;
//}
}
感谢。