Database Reference
In-Depth Information
.tuple("first","second","third"));
builder.setSpout("spout2",
new
LoremIpsumSpout()
.tuple("second","third","forth"));
Then, just to give the topology something to do, attach a
FilterBolt
from the last section. Have it filter on two well-known parts of the
“lorem ipsum” text. Note that the filter takes in both spouts:
builder.setBolt("filter",
new
FilterBolt()
.filter("ipsum", "first", ".*ipsum.*","first")
.filter("amet","second",".*amet.*","second")
).shuffleGrouping("spout1")
.shuffleGrouping("spout2")
;
To see the filtering functionality, use a
LoggerBolt
to print the
output. It also identifies the source stream to show that the filter
actually works:
builder.setBolt("print",
new
LoggerBolt())
.shuffleGrouping("filter","amet")
.shuffleGrouping("filter","ipsum");
This is all then submitted to a
LocalCluster
for execution:
Config conf =
new
Config();
LocalCluster cluster =
new
LocalCluster();
cluster.submitTopology("example", conf,
builder.createTopology());
Finally, have the main class sleep for a bit. Because
LocalCluster
is
running an embedded topology, most of the work is being done in
background threads:
//Sleep for a minute
Thread.
sleep
(60000);