Database Reference
In-Depth Information
}
}
Tip
Downloading the example code
You can download the example code files for all the Packt topics you have purchased
from your account at
http://www.packtpub.com
.
If you purchased this topic elsewhere,
you can visit
http://www.packtpub.com/support
and register to have the files e-mailed dir-
ectly to you.
Tweaking WordCount topology to use FileSpout
Now we need to fit
FileSpout
into our
WordCount
topology and execute it. To do
this, you need to change one line of code in
WordCount
topology and instantiate
FileSpout
instead of
RandomSentenceSpout
in
TopologyBuilder
, as shown
here:
public static void main(String[] args) throws Exception {
TopologyBuilder builder = new TopologyBuilder();
//builder.setSpout("spout", new RandomSentenceSpout(), 5);
builder.setSpout("spout", new FileSpout(), 1);
This one line change will take care of instantiation of the new spout that will read from
the specified file
/home/mylog
(please create this file before you execute the program).
Here is a screenshot of the output for your reference:
The SocketSpout class
As a next step to understand the spouts better, let's create a
SocketSpout
class. Assum-
ing that you are proficient in writing Socket Server or Producer, I will walk you through
Search WWH ::
Custom Search