Database Reference
In-Depth Information
Creating FileSpout
Here we will create our own spout to read the events or tuples from a file source and emit
them into the topology; we would substitute spout in place of RandomSentenceSpout
we used in the WordCount topology in the previous chapter.
To start, copy the project we created in Chapter 2 , Getting Started with Your First Topo-
logy , into a new project and make the following changes in RandomSentenceSpout to
make a new class called FileSpout within the Storm-starter project.
Now we will make changes in FileSpout so that it reads sentences from a file as shown
in the following code:
public class FileSpout extends BaseRichSpout {
//declaration section
SpoutOutputCollector _collector;
DataInputStream in ;
BufferedReader br;
Queue qe;
//constructor
public FileSpout() {
qe = new LinkedList();
}
// the messageId builder method
private String getMsgId(int i) {
return (new
StringBuilder("#@#MsgId")).append(i).toString();
}
//The function that is called at every line being read by
readFile
//method and adds messageId at the end of each line and
then add
// the line to the linked list
private void queueIt() {
int msgId = 0;
Search WWH ::




Custom Search