use of org.apache.storm.topology.TopologyBuilder in project storm by apache.
the class AnchoredWordCount method run.
protected int run(String[] args) throws Exception {
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("spout", new RandomSentenceSpout(), 4);
builder.setBolt("split", new SplitSentence(), 4).shuffleGrouping("spout");
builder.setBolt("count", new WordCount(), 4).fieldsGrouping("split", new Fields("word"));
Config conf = new Config();
conf.setMaxTaskParallelism(3);
String topologyName = "word-count";
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 JoinBoltExample method main.
public static void main(String[] args) throws Exception {
if (!NimbusClient.isLocalOverride()) {
throw new IllegalStateException("This example only works in local mode. " + "Run with storm local not storm jar");
}
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();
StormSubmitter.submitTopologyWithProgressBar("join-example", conf, builder.createTopology());
generateGenderData(genderSpout);
generateAgeData(ageSpout);
}
use of org.apache.storm.topology.TopologyBuilder in project storm by apache.
the class SolrFieldsTopology method getTopology.
@Override
protected StormTopology getTopology() throws IOException {
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("SolrFieldsSpout", new SolrFieldsSpout());
SolrConfig solrConfig = getSolrConfig();
builder.setBolt("SolrUpdateBolt", new SolrUpdateBolt(solrConfig, getSolrMapper(solrConfig), getSolrCommitStgy())).shuffleGrouping("SolrFieldsSpout");
return builder.createTopology();
}
use of org.apache.storm.topology.TopologyBuilder in project storm by apache.
the class WordCountTopology method buildTopology.
public static StormTopology buildTopology(String nameserverAddr, String topic) {
Properties properties = new Properties();
properties.setProperty(SpoutConfig.NAME_SERVER_ADDR, nameserverAddr);
properties.setProperty(SpoutConfig.CONSUMER_GROUP, CONSUMER_GROUP);
properties.setProperty(SpoutConfig.CONSUMER_TOPIC, CONSUMER_TOPIC);
RocketMqSpout spout = new RocketMqSpout(properties);
TupleToMessageMapper mapper = new FieldNameBasedTupleToMessageMapper("word", "count");
TopicSelector selector = new DefaultTopicSelector(topic);
properties = new Properties();
properties.setProperty(RocketMqConfig.NAME_SERVER_ADDR, nameserverAddr);
RocketMqBolt insertBolt = new RocketMqBolt().withMapper(mapper).withSelector(selector).withProperties(properties);
// wordSpout ==> countBolt ==> insertBolt
TopologyBuilder builder = new TopologyBuilder();
WordCounter bolt = new WordCounter();
builder.setSpout(WORD_SPOUT, spout, 1);
builder.setBolt(COUNT_BOLT, bolt, 1).fieldsGrouping(WORD_SPOUT, new Fields("str"));
builder.setBolt(INSERT_BOLT, insertBolt, 1).shuffleGrouping(COUNT_BOLT);
return builder.createTopology();
}
use of org.apache.storm.topology.TopologyBuilder in project storm by apache.
the class SolrJsonTopology method getTopology.
@Override
protected StormTopology getTopology() throws IOException {
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("SolrJsonSpout", new SolrJsonSpout());
builder.setBolt("SolrUpdateBolt", new SolrUpdateBolt(getSolrConfig(), getSolrMapper(), getSolrCommitStgy())).shuffleGrouping("SolrJsonSpout");
return builder.createTopology();
}
Aggregations