use of backtype.storm.topology.TopologyBuilder in project ud381 by udacity.
the class SentenceCountTopology 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 5
// builder.setSpout("word-spout", new WordSpout(), 5);
// attach sentence spout to the topology - parallelism of 1
builder.setSpout("sentence-spout", new RandomSentenceSpout(), 1);
// attach the count bolt using fields grouping - parallelism of 15
builder.setBolt("count-bolt", new CountBolt(), 15).fieldsGrouping("sentence-spout", new Fields("sentence"));
// attach the report bolt using global grouping - parallelism of 1
// ***************************************************
// BEGIN YOUR CODE - part 2
builder.setBolt("report-bolt", new ReportBolt(), 1).globalGrouping("count-bolt");
// END YOUR CODE
// ***************************************************
// 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
// set the number of threads to run - similar to setting number of workers in live cluster
conf.setMaxTaskParallelism(3);
// create the local cluster instance
LocalCluster cluster = new LocalCluster();
// submit the topology to the local cluster
// name topology
cluster.submitTopology("sentence-count", conf, builder.createTopology());
// **********************************************************************
// let the topology run for 30 seconds. note topologies never terminate!
Thread.sleep(30000);
// **********************************************************************
// we are done, so shutdown the local cluster
cluster.shutdown();
}
}
use of backtype.storm.topology.TopologyBuilder in project storm-hbase by ypf412.
the class OutputTopology method main.
/**
* HBase Data Output Topology
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
TopologyBuilder builder = new TopologyBuilder();
PropConfig pc = new PropConfig("storm.properties");
int topoWorkers = Integer.valueOf(pc.getProperty("storm.topolopy.workers"));
int spoutTasks = Integer.valueOf(pc.getProperty("storm.spout.tasks"));
builder.setSpout("hbaseSpout", new HBaseSpout(), spoutTasks);
int boltTasks = spoutTasks;
builder.setBolt("outputBolt", new OutputBolt(), boltTasks).fieldsGrouping("hbaseSpout", new Fields("sharding"));
Config conf = new Config();
conf.put(Constants.STORM_PROP_CONF_FILE, "storm.properties");
conf.put(Constants.HBASE_PROP_CONF_FILE, "hbase.properties");
if (args != null && args.length > 0) {
// run on storm cluster
conf.setNumAckers(1);
conf.setNumWorkers(topoWorkers);
StormSubmitter.submitTopology(args[0], conf, builder.createTopology());
} else {
// run on local cluster
conf.setMaxTaskParallelism(3);
LocalCluster cluster = new LocalCluster();
cluster.submitTopology("test", conf, builder.createTopology());
Utils.sleep(10000);
cluster.killTopology("test");
cluster.shutdown();
}
}
use of backtype.storm.topology.TopologyBuilder in project avro-kafka-storm by ransilberman.
the class AvroTopology method main.
public static void main(String[] args) throws AlreadyAliveException, InvalidTopologyException {
// Add those lines to prevent too much logging noise in the console
Logger.getLogger("storm.kafka.PartitionManager").setLevel(Level.ERROR);
Logger.getLogger("backtype.storm").setLevel(Level.ERROR);
Logger.getLogger("storm.kafka").setLevel(Level.ERROR);
TopologyBuilder builder = new TopologyBuilder();
int partitions = 1;
final String offsetPath = "/liveperson-avro-test";
final String consumerId = "v1";
final String topic = "avro-test";
List<String> hosts = new ArrayList<String>();
hosts.add("tlvwhale1");
hosts.add("tlvwhale2");
hosts.add("tlvwhale3");
SpoutConfig kafkaConfig = new SpoutConfig(KafkaConfig.StaticHosts.fromHostString(hosts, partitions), topic, offsetPath, consumerId);
KafkaSpout kafkaSpout = new KafkaSpout(kafkaConfig);
builder.setSpout("spout", kafkaSpout);
builder.setBolt("bolt", new AvroBolt()).shuffleGrouping("spout");
Config conf = new Config();
conf.setDebug(true);
if (args != null && args.length > 0) {
conf.setNumWorkers(3);
StormSubmitter.submitTopology(args[0], conf, builder.createTopology());
} else {
LocalCluster cluster = new LocalCluster();
cluster.submitTopology("avroTopology", conf, builder.createTopology());
Utils.sleep(100000);
cluster.killTopology("avroTopology");
cluster.shutdown();
}
}
use of backtype.storm.topology.TopologyBuilder in project avro-kafka-storm by ransilberman.
the class AvroTopology2 method main.
public static void main(String[] args) throws AlreadyAliveException, InvalidTopologyException {
// Add those lines to prevent too much logging noise in the console
Logger.getLogger("storm.kafka.PartitionManager").setLevel(Level.ERROR);
Logger.getLogger("backtype.storm").setLevel(Level.ERROR);
Logger.getLogger("storm.kafka").setLevel(Level.ERROR);
TopologyBuilder builder = new TopologyBuilder();
int partitions = 1;
final String offsetPath = "/liveperson-avro-test";
final String consumerId = "v1";
final String topic = "avro-test";
List<String> hosts = new ArrayList<String>();
hosts.add("tlvwhale1");
hosts.add("tlvwhale2");
hosts.add("tlvwhale3");
SpoutConfig kafkaConfig = new SpoutConfig(KafkaConfig.StaticHosts.fromHostString(hosts, partitions), topic, offsetPath, consumerId);
KafkaSpout kafkaSpout = new KafkaSpout(kafkaConfig);
builder.setSpout("spout", kafkaSpout);
builder.setBolt("bolt", new AvroBolt()).shuffleGrouping("spout");
Config conf = new Config();
conf.setDebug(true);
if (args != null && args.length > 0) {
conf.setNumWorkers(3);
StormSubmitter.submitTopology(args[0], conf, builder.createTopology());
} else {
LocalCluster cluster = new LocalCluster();
cluster.submitTopology("avroTopology", conf, builder.createTopology());
Utils.sleep(1000000);
cluster.killTopology("avroTopology");
cluster.shutdown();
}
}
use of backtype.storm.topology.TopologyBuilder in project heron by twitter.
the class WordCountTopology method main.
/**
* Main method
*/
public static void main(String[] args) throws AlreadyAliveException, InvalidTopologyException {
if (args.length < 1) {
throw new RuntimeException("Specify topology name");
}
int parallelism = 1;
if (args.length > 1) {
parallelism = Integer.parseInt(args[1]);
}
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("word", new WordSpout(), parallelism);
builder.setBolt("consumer", new ConsumerBolt(), parallelism).fieldsGrouping("word", new Fields("word"));
Config conf = new Config();
conf.setNumWorkers(parallelism);
StormSubmitter.submitTopology(args[0], conf, builder.createTopology());
}
Aggregations