Basic Storm Trident topology
Here, in basic Storm Trident topology we will go through a word count example. More examples will be explained later in the chapter. This is the code for the example:
FixedBatchSpout spout = new FixedBatchSpout(new Fields("sentence"), 3, new Values("this is simple example of trident topology"), new Values("this example count same words")); spout.setCycle(true); // Line 1 TridentTopology topology = new TridentTopology(); // Line 2 MemoryMapState.Factory stateFactory = new MemoryMapState.Factory(); // Line 3 topology.newStream("spout1", spout) // Line 4 .each(new Fields("sentence"), new Split(), new Fields("word")) // Line 5 .groupBy(new Fields("word")) // Line 6 .persistentAggregate(stateFactory, new Count(), new Fields("count")).newValuesStream() // Line 7 .filter(new DisplayOutputFilter()) // Line 8 .parallelismHint(6); // Line 9 Config config = new Config(); // Line 10 config.setNumWorkers(3); // Line 11 LocalCluster cluster = new LocalCluster(); // Line 12...