Search in sources :

Example 66 with TopologyBuilder

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);
}
Also used : Fields(org.apache.storm.tuple.Fields) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Config(org.apache.storm.Config)

Example 67 with TopologyBuilder

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);
}
Also used : Fields(org.apache.storm.tuple.Fields) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Config(org.apache.storm.Config) JoinBolt(org.apache.storm.bolt.JoinBolt) FeederSpout(org.apache.storm.testing.FeederSpout) PrinterBolt(org.apache.storm.starter.bolt.PrinterBolt) BaseWindowedBolt(org.apache.storm.topology.base.BaseWindowedBolt)

Example 68 with TopologyBuilder

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();
}
Also used : SolrConfig(org.apache.storm.solr.config.SolrConfig) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) SolrUpdateBolt(org.apache.storm.solr.bolt.SolrUpdateBolt) SolrFieldsSpout(org.apache.storm.solr.spout.SolrFieldsSpout)

Example 69 with TopologyBuilder

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();
}
Also used : FieldNameBasedTupleToMessageMapper(org.apache.storm.rocketmq.common.mapper.FieldNameBasedTupleToMessageMapper) Fields(org.apache.storm.tuple.Fields) TupleToMessageMapper(org.apache.storm.rocketmq.common.mapper.TupleToMessageMapper) FieldNameBasedTupleToMessageMapper(org.apache.storm.rocketmq.common.mapper.FieldNameBasedTupleToMessageMapper) RocketMqBolt(org.apache.storm.rocketmq.bolt.RocketMqBolt) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) TopicSelector(org.apache.storm.rocketmq.common.selector.TopicSelector) DefaultTopicSelector(org.apache.storm.rocketmq.common.selector.DefaultTopicSelector) RocketMqSpout(org.apache.storm.rocketmq.spout.RocketMqSpout) DefaultTopicSelector(org.apache.storm.rocketmq.common.selector.DefaultTopicSelector) Properties(java.util.Properties)

Example 70 with TopologyBuilder

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();
}
Also used : TopologyBuilder(org.apache.storm.topology.TopologyBuilder) SolrUpdateBolt(org.apache.storm.solr.bolt.SolrUpdateBolt) SolrJsonSpout(org.apache.storm.solr.spout.SolrJsonSpout)

Aggregations

TopologyBuilder (org.apache.storm.topology.TopologyBuilder)266 Config (org.apache.storm.Config)141 Fields (org.apache.storm.tuple.Fields)76 StormTopology (org.apache.storm.generated.StormTopology)47 HashMap (java.util.HashMap)41 LocalCluster (org.apache.storm.LocalCluster)39 TestWordSpout (org.apache.storm.testing.TestWordSpout)34 TopologyDetails (org.apache.storm.scheduler.TopologyDetails)26 Test (org.junit.Test)26 Test (org.junit.jupiter.api.Test)26 Cluster (org.apache.storm.scheduler.Cluster)25 SupervisorDetails (org.apache.storm.scheduler.SupervisorDetails)25 Topologies (org.apache.storm.scheduler.Topologies)25 Values (org.apache.storm.tuple.Values)25 TestUtilsForResourceAwareScheduler (org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler)24 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)24 Map (java.util.Map)23 INimbus (org.apache.storm.scheduler.INimbus)23 StormMetricsRegistry (org.apache.storm.metric.StormMetricsRegistry)22 ResourceMetrics (org.apache.storm.scheduler.resource.normalization.ResourceMetrics)22