Spouts must implement the ISpout interface.
public interface ISpout extends Serializable {
void open(Map<String, Object> conf, TopologyContext context, SpoutOutputCollector collector);
void close();
void activate();
void deactivate();
void nextTuple();
void ack(Object msgId);
void fail(Object msgId);
}
The
openmethod is called when the spout is initialized and provides the spout with the executing environment.The
closemethod is called when the spout is shutdown. There’s no guarantee that this method is called due to how the instance is killed.The
activatemethod is called when the spout is asked to back into active state.The
deactivatemethod is called when the spout is asked to enter deactive state.The
nextTuplemethod is used to fetch tuples from input source and emit it toOutputCollector.The
ackmethod is called when theTuplewith themsgIdemitted by this spout is successfully processed.The
failmethod is called when theTuplewith themsgIdemitted by this spout is not processed successfully.
See TestWordSpout for a simple spout example.
Instead of implementing the ISpout interface directly, you can implement IRichSpout.