Search in sources :

Example 46 with TopologyBuilder

use of org.apache.storm.topology.TopologyBuilder in project storm by apache.

the class SlidingWindowTopology method main.

public static void main(String[] args) throws Exception {
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("integer", new RandomIntegerSpout(), 1);
    builder.setBolt("slidingsum", new SlidingWindowSumBolt().withWindow(Count.of(30), Count.of(10)), 1).shuffleGrouping("integer");
    builder.setBolt("tumblingavg", new TumblingWindowAvgBolt().withTumblingWindow(Count.of(3)), 1).shuffleGrouping("slidingsum");
    builder.setBolt("printer", new PrinterBolt(), 1).shuffleGrouping("tumblingavg");
    Config conf = new Config();
    conf.setDebug(true);
    String topoName = "test";
    if (args != null && args.length > 0) {
        topoName = args[0];
    }
    conf.setNumWorkers(1);
    StormSubmitter.submitTopologyWithProgressBar(topoName, conf, builder.createTopology());
}
Also used : TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Config(org.apache.storm.Config) RandomIntegerSpout(org.apache.storm.starter.spout.RandomIntegerSpout) SlidingWindowSumBolt(org.apache.storm.starter.bolt.SlidingWindowSumBolt) PrinterBolt(org.apache.storm.starter.bolt.PrinterBolt)

Example 47 with TopologyBuilder

use of org.apache.storm.topology.TopologyBuilder in project storm by apache.

the class StatefulWindowingTopology method main.

public static void main(String[] args) throws Exception {
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("spout", new RandomIntegerSpout());
    builder.setBolt("sumbolt", new WindowSumBolt().withWindow(new Count(5), new Count(3)).withMessageIdField("msgid"), 1).shuffleGrouping("spout");
    builder.setBolt("printer", new PrinterBolt(), 1).shuffleGrouping("sumbolt");
    Config conf = new Config();
    conf.setDebug(false);
    // conf.put(Config.TOPOLOGY_STATE_PROVIDER, "org.apache.storm.redis.state.RedisKeyValueStateProvider");
    String topoName = "test";
    if (args != null && args.length > 0) {
        topoName = args[0];
    }
    conf.setNumWorkers(1);
    StormSubmitter.submitTopologyWithProgressBar(topoName, conf, builder.createTopology());
}
Also used : TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Config(org.apache.storm.Config) RandomIntegerSpout(org.apache.storm.starter.spout.RandomIntegerSpout) Count(org.apache.storm.topology.base.BaseWindowedBolt.Count) PrinterBolt(org.apache.storm.starter.bolt.PrinterBolt)

Example 48 with TopologyBuilder

use of org.apache.storm.topology.TopologyBuilder in project storm by apache.

the class WordCountTopologyNode method main.

public static void main(String[] args) throws Exception {
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("spout", new RandomSentence(), 5);
    builder.setBolt("split", new SplitSentence(), 8).shuffleGrouping("spout");
    builder.setBolt("count", new WordCount(), 12).fieldsGrouping("split", new Fields("word"));
    Config conf = new Config();
    conf.setDebug(true);
    String topoName = "word-count";
    if (args != null && args.length > 0) {
        topoName = args[0];
    }
    conf.setNumWorkers(3);
    StormSubmitter.submitTopologyWithProgressBar(topoName, conf, builder.createTopology());
}
Also used : Fields(org.apache.storm.tuple.Fields) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Config(org.apache.storm.Config)

Example 49 with TopologyBuilder

use of org.apache.storm.topology.TopologyBuilder in project storm by apache.

the class StormMqttIntegrationTest method buildMqttTopology.

public StormTopology buildMqttTopology() {
    TopologyBuilder builder = new TopologyBuilder();
    MqttOptions options = new MqttOptions();
    options.setTopics(Arrays.asList(TEST_TOPIC));
    options.setCleanConnection(false);
    TestSpout spout = new TestSpout(new StringMessageMapper(), options);
    MqttBolt bolt = new MqttBolt(options, new MqttTupleMapper() {

        @Override
        public MqttMessage toMessage(ITuple tuple) {
            LOG.info("Received: {}", tuple);
            return new MqttMessage(RESULT_TOPIC, RESULT_PAYLOAD.getBytes());
        }
    });
    builder.setSpout("mqtt-spout", spout);
    builder.setBolt("mqtt-bolt", bolt).shuffleGrouping("mqtt-spout");
    return builder.createTopology();
}
Also used : MqttOptions(org.apache.storm.mqtt.common.MqttOptions) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) MqttBolt(org.apache.storm.mqtt.bolt.MqttBolt) ITuple(org.apache.storm.tuple.ITuple) StringMessageMapper(org.apache.storm.mqtt.mappers.StringMessageMapper)

Example 50 with TopologyBuilder

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();
}
Also used : LogInfoBolt(org.apache.storm.flux.wrappers.bolts.LogInfoBolt) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) FluxShellSpout(org.apache.storm.flux.wrappers.spouts.FluxShellSpout)

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