use of org.apache.storm.topology.TopologyBuilder in project storm by apache.
the class JoinBoltExample method main.
public static void main(String[] args) throws Exception {
FeederSpout genderSpout = new FeederSpout(new Fields("id", "gender"));
FeederSpout ageSpout = new FeederSpout(new Fields("id", "age"));
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("genderSpout", genderSpout);
builder.setSpout("ageSpout", ageSpout);
// inner join of 'age' and 'gender' records on 'id' field
JoinBolt joiner = new JoinBolt("genderSpout", "id").join("ageSpout", "id", "genderSpout").select("genderSpout:id,ageSpout:id,gender,age").withTumblingWindow(new BaseWindowedBolt.Duration(10, TimeUnit.SECONDS));
builder.setBolt("joiner", joiner).fieldsGrouping("genderSpout", new Fields("id")).fieldsGrouping("ageSpout", new Fields("id"));
builder.setBolt("printer", new PrinterBolt()).shuffleGrouping("joiner");
Config conf = new Config();
conf.setDebug(true);
LocalCluster cluster = new LocalCluster();
cluster.submitTopology("join-example", conf, builder.createTopology());
generateGenderData(genderSpout);
generateAgeData(ageSpout);
Utils.sleep(30000);
cluster.shutdown();
}
use of org.apache.storm.topology.TopologyBuilder in project storm by apache.
the class SingleJoinExample method main.
public static void main(String[] args) throws Exception {
FeederSpout genderSpout = new FeederSpout(new Fields("id", "gender"));
FeederSpout ageSpout = new FeederSpout(new Fields("id", "age"));
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("gender", genderSpout);
builder.setSpout("age", ageSpout);
builder.setBolt("join", new SingleJoinBolt(new Fields("gender", "age"))).fieldsGrouping("gender", new Fields("id")).fieldsGrouping("age", new Fields("id"));
Config conf = new Config();
conf.setDebug(true);
try (LocalCluster cluster = new LocalCluster();
LocalTopology topo = cluster.submitTopology("join-example", conf, builder.createTopology())) {
for (int i = 0; i < 10; i++) {
String gender;
if (i % 2 == 0) {
gender = "male";
} else {
gender = "female";
}
genderSpout.feed(new Values(i, gender));
}
for (int i = 9; i >= 0; i--) {
ageSpout.feed(new Values(i, i + 20));
}
Utils.sleep(2000);
}
}
use of org.apache.storm.topology.TopologyBuilder in project storm by apache.
the class SkewedRollingTopWords method run.
/**
* Submits (runs) the topology.
*
* Usage: "SkewedRollingTopWords [topology-name] [-local]"
*
* By default, the topology is run locally under the name
* "slidingWindowCounts".
*
* Examples:
*
* ```
*
* # Runs in local mode (LocalCluster), with topology name "slidingWindowCounts"
* $ storm jar storm-starter-jar-with-dependencies.jar org.apache.storm.starter.SkewedRollingTopWords -local
*
* # Runs in local mode (LocalCluster), with topology name "foobar"
* $ storm jar storm-starter-jar-with-dependencies.jar org.apache.storm.starter.SkewedRollingTopWords foobar -local
*
* # Runs in local mode (LocalCluster) for 30 seconds, with topology name "foobar"
* $ storm jar storm-starter-jar-with-dependencies.jar org.apache.storm.starter.SkewedRollingTopWords foobar -local -ttl 30
*
* # Runs in remote/cluster mode, with topology name "production-topology"
* $ storm jar storm-starter-jar-with-dependencies.jar org.apache.storm.starter.SkewedRollingTopWords production-topology ```
*
* @param args
* First positional argument (optional) is topology name, second
* positional argument (optional) defines whether to run the topology
* locally ("-local") or remotely, i.e. on a real cluster.
* @throws Exception
*/
protected int run(String[] args) {
String topologyName = "slidingWindowCounts";
if (args.length >= 1) {
topologyName = args[0];
}
TopologyBuilder builder = new TopologyBuilder();
String spoutId = "wordGenerator";
String counterId = "counter";
String aggId = "aggregator";
String intermediateRankerId = "intermediateRanker";
String totalRankerId = "finalRanker";
builder.setSpout(spoutId, new TestWordSpout(), 5);
builder.setBolt(counterId, new RollingCountBolt(9, 3), 4).partialKeyGrouping(spoutId, new Fields("word"));
builder.setBolt(aggId, new RollingCountAggBolt(), 4).fieldsGrouping(counterId, new Fields("obj"));
builder.setBolt(intermediateRankerId, new IntermediateRankingsBolt(TOP_N), 4).fieldsGrouping(aggId, new Fields("obj"));
builder.setBolt(totalRankerId, new TotalRankingsBolt(TOP_N)).globalGrouping(intermediateRankerId);
LOG.info("Topology name: " + topologyName);
return submit(topologyName, conf, builder);
}
use of org.apache.storm.topology.TopologyBuilder in project storm by apache.
the class ExclamationTopology method run.
protected int run(String[] args) {
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("word", new TestWordSpout(), 10);
builder.setBolt("exclaim1", new ExclamationBolt(), 3).shuffleGrouping("word");
builder.setBolt("exclaim2", new ExclamationBolt(), 2).shuffleGrouping("exclaim1");
conf.setDebug(true);
String topologyName = "test";
if (isLocal) {
ttl = 10;
} else {
conf.setNumWorkers(3);
}
if (args != null && args.length > 0) {
topologyName = args[0];
}
return submit(topologyName, conf, builder);
}
use of org.apache.storm.topology.TopologyBuilder in project storm by apache.
the class SimpleTopology method getTopology.
public StormTopology getTopology(Map<String, Object> config) {
TopologyBuilder builder = new TopologyBuilder();
// spouts
FluxShellSpout spout = new FluxShellSpout(new String[] { "node", "randomsentence.js" }, new String[] { "word" });
builder.setSpout("sentence-spout", spout, 1);
// bolts
builder.setBolt("log-bolt", new LogInfoBolt(), 1).shuffleGrouping("sentence-spout");
return builder.createTopology();
}
Aggregations