Skip to content

Instantly share code, notes, and snippets.

Created December 11, 2012 22:01
Show Gist options
  • Save anonymous/4262668 to your computer and use it in GitHub Desktop.
Save anonymous/4262668 to your computer and use it in GitHub Desktop.
A sample barebones spout
public class SampleSpout extends BaseRichSpout {
private SpoutOutputCollector collector;
@Override
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
this.collector = collector;
/*
* Connect to your data source here
* Eg. Run a query and store a reference to the cursor
*/
}
@Override
public void nextTuple() {
/*
* Iterate through the stored cursor ref and push out
* one "row" into the collector as a Tuple
*/
collector.emit("default", new Values("val1", "val2", new Object()));
}
@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
/*
* Schema declaration of the stream
*/
declarer.declareStream("default", new Fields("tweet"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment