Strom Spouts
Spouts
A spout is a source of streams in a topology. Generally spouts will read tuples from an external source and emit them into the topology (e.g. a Kestrel queue or the Twitter API). Spouts can either be reliable or unreliable. A reliable spout is capable(能胜任的) of replaying a tuple if it failed to be processed by Storm, whereas an unreliable spout forgets about the tuple as soon as it is emitted.
Spouts can emit more than one stream. To do so, declare multiple streams using the declareStream
method
of OutputFieldsDeclarer and specify the stream to emit to when using
the emit
method on SpoutOutputCollector.
The main method on spouts is nextTuple
. nextTuple
either
emits a new tuple into the topology or simply returns if there are no new tuples to emit. It is imperative(不可避免的) that nextTuple
does
not block for any spout implementation, because Storm calls all the spout methods on the same thread.
The other main methods on spouts are ack
and fail
.
These are called when Storm detects that a tuple emitted from the spout either successfully completed through the topology or failed to be completed. ack
and fail
are
only called for reliable spouts. See the Javadoc for more information.
Resources:
- IRichSpout: this is the interface that spouts must implement.
- Guaranteeing message processing