Search in sources :

Example 1 with MyLikesSpout

use of udacity.storm.spout.MyLikesSpout in project ud381 by udacity.

the class ExclamationTopology method main.

public static void main(String[] args) throws Exception {
    // create the topology
    TopologyBuilder builder = new TopologyBuilder();
    // attach the word spout to the topology - parallelism of 10
    //builder.setSpout("word", new TestWordSpout(), 10);
    //******** Add MyLikesSpout and MyNamesSpout
    builder.setSpout("my-likes", new MyLikesSpout(), 10);
    builder.setSpout("my-names", new MyNamesSpout(), 10);
    // attach the exclamation bolt to the topology - parallelism of 3
    builder.setBolt("exclaim1", new ExclamationBolt(), 3).shuffleGrouping("my-likes").shuffleGrouping("my-names");
    // attach another exclamation bolt to the topology - parallelism of 2
    builder.setBolt("exclaim2", new ExclamationBolt(), 2).shuffleGrouping("exclaim1");
    //******* Attach ReportBolt
    builder.setBolt("report-bolt", new ReportBolt(), 1).globalGrouping("exclaim2");
    // create the default config object
    Config conf = new Config();
    // set the config in debugging mode
    conf.setDebug(true);
    if (args != null && args.length > 0) {
        // run it in a live cluster
        // set the number of workers for running all spout and bolt tasks
        conf.setNumWorkers(3);
        // create the topology and submit with config
        StormSubmitter.submitTopology(args[0], conf, builder.createTopology());
    } else {
        // run it in a simulated local cluster
        // create the local cluster instance
        LocalCluster cluster = new LocalCluster();
        // submit the topology to the local cluster
        cluster.submitTopology("exclamation", conf, builder.createTopology());
        // let the topology run for 30 seconds. note topologies never terminate!
        Thread.sleep(30000);
        // kill the topology
        cluster.killTopology("exclamation");
        // we are done, so shutdown the local cluster
        cluster.shutdown();
    }
}
Also used : LocalCluster(backtype.storm.LocalCluster) TopologyBuilder(backtype.storm.topology.TopologyBuilder) Config(backtype.storm.Config) MyNamesSpout(udacity.storm.spout.MyNamesSpout) MyLikesSpout(udacity.storm.spout.MyLikesSpout)

Aggregations

Config (backtype.storm.Config)1 LocalCluster (backtype.storm.LocalCluster)1 TopologyBuilder (backtype.storm.topology.TopologyBuilder)1 MyLikesSpout (udacity.storm.spout.MyLikesSpout)1 MyNamesSpout (udacity.storm.spout.MyNamesSpout)1