Skip to content

Instantly share code, notes, and snippets.

@lovelock
Last active August 28, 2016 10:15
Show Gist options
  • Save lovelock/82066d33873f3fa8cf0b12d006ccc6ff to your computer and use it in GitHub Desktop.
Save lovelock/82066d33873f3fa8cf0b12d006ccc6ff to your computer and use it in GitHub Desktop.
general storm topology main method
public static void main(String[] args) throw Exception {
TopologyBuilder builder = new TopologyBuilder();
String spout_id = "spout";
String bolt1_id = "bolt1";
String bolt2_id = "bolt2";
MySpout spout = new MySpout();
MyBolt1 bolt1 = new MyBolt1();
MyBolt2 bolt2 = new MyBolt2();
builder.setSpout(spout_id, spout, 2).setNumTasks(4);
builder.setBolt(bolt1_id, bolt1, 8).shuffleGrouping(spout_id);
builder.setBolt(bolt2_id, bolt2, 2).filedsGrouping(bolt1_id, new Fields("word"));
Config config = new Config();
if (args != null && args.length > 0) {
config.setDebug(false);
config.put(Config.NIMBUS_HOST, "172.16.74.136");
config.setNumWorkers(4);
StormSubmitter.submit(args[0], config, builder.createTopology());
} else {
config.setDebug(true);
LocalCluster cluster = new LocalCluster();
cluster.submit("local", config, builder.createTopology());
Thread.sleep(10000);
cluster.shutdown();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment