Database Reference
In-Depth Information
A Logging Bolt
The logging bolt is a very simple
Bolt
implementation that is useful
when testing topologies. All it does is print the results of an input tuple
to the console. This can be very useful when testing topologies, and it is
easy to implement with a
BasicBolt
. This bolt doesn't produce any
data, and just uses the fact that
Tuple
implements a reasonable
toString
method:
public class
LoggerBolt
extends
BaseBasicBolt {
private static final
Logger
LOG
= Logger.
getLogger
(LoggerBolt.
class
);
private static final long
serialVersionUID
= 1L;
public void
execute(Tuple input,
BasicOutputCollector collector) {
LOG
.info(input.toString());
}
public void
declareOutputFields(OutputFieldsDeclarer declarer) {
}
}
Implementing and Using Spouts
The
Spout
is a special form of Storm topology element that is responsible
for retrieving data from the outside world. Unlike
Bolts
, there is only an
IRichSpout
interface to implement and no base class to derive from.
When a
Spout
is created, the open method is called first. This allows the
Spout
to configure any connections to the outside world, such as
connectionstoqueueordatamotionservers.Likea
Bolt
,the
Spout
should
capture its
SpoutOutputCollector
from the open method for later use:
public class
EmptySpout
implements
IRichSpout {
transient
SpoutOutputCollector collector;
public void
open(Map conf, TopologyContext context,