Search in sources :

Example 16 with LocalCluster

use of org.apache.storm.LocalCluster in project storm by apache.

the class SlidingTupleTsTopology method main.

public static void main(String[] args) throws Exception {
    TopologyBuilder builder = new TopologyBuilder();
    BaseWindowedBolt bolt = new SlidingWindowSumBolt().withWindow(new Duration(5, TimeUnit.SECONDS), new Duration(3, TimeUnit.SECONDS)).withTimestampField("ts").withLag(new Duration(5, TimeUnit.SECONDS));
    builder.setSpout("integer", new RandomIntegerSpout(), 1);
    builder.setBolt("slidingsum", bolt, 1).shuffleGrouping("integer");
    builder.setBolt("printer", new PrinterBolt(), 1).shuffleGrouping("slidingsum");
    Config conf = new Config();
    conf.setDebug(true);
    if (args != null && args.length > 0) {
        conf.setNumWorkers(1);
        StormSubmitter.submitTopologyWithProgressBar(args[0], conf, builder.createTopology());
    } else {
        try (LocalCluster cluster = new LocalCluster();
            LocalTopology topo = cluster.submitTopology("test", conf, builder.createTopology())) {
            Utils.sleep(40000);
        }
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Config(org.apache.storm.Config) RandomIntegerSpout(org.apache.storm.starter.spout.RandomIntegerSpout) Duration(org.apache.storm.topology.base.BaseWindowedBolt.Duration) SlidingWindowSumBolt(org.apache.storm.starter.bolt.SlidingWindowSumBolt) PrinterBolt(org.apache.storm.starter.bolt.PrinterBolt) LocalTopology(org.apache.storm.LocalCluster.LocalTopology) BaseWindowedBolt(org.apache.storm.topology.base.BaseWindowedBolt)

Example 17 with LocalCluster

use of org.apache.storm.LocalCluster 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);
    if (args != null && args.length > 0) {
        conf.setNumWorkers(1);
        StormSubmitter.submitTopologyWithProgressBar(args[0], conf, builder.createTopology());
    } else {
        try (LocalCluster cluster = new LocalCluster();
            LocalTopology topo = cluster.submitTopology("test", conf, builder.createTopology())) {
            Utils.sleep(40000);
        }
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) 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) LocalTopology(org.apache.storm.LocalCluster.LocalTopology)

Example 18 with LocalCluster

use of org.apache.storm.LocalCluster in project storm by apache.

the class TransactionalGlobalCount method main.

public static void main(String[] args) throws Exception {
    MemoryTransactionalSpout spout = new MemoryTransactionalSpout(DATA, new Fields("word"), PARTITION_TAKE_PER_BATCH);
    TransactionalTopologyBuilder builder = new TransactionalTopologyBuilder("global-count", "spout", spout, 3);
    builder.setBolt("partial-count", new BatchCount(), 5).noneGrouping("spout");
    builder.setBolt("sum", new UpdateGlobalCount()).globalGrouping("partial-count");
    Config config = new Config();
    config.setDebug(true);
    config.setMaxSpoutPending(3);
    try (LocalCluster cluster = new LocalCluster();
        LocalTopology topo = cluster.submitTopology("global-count-topology", config, builder.buildTopology())) {
        Thread.sleep(3000);
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) MemoryTransactionalSpout(org.apache.storm.testing.MemoryTransactionalSpout) Fields(org.apache.storm.tuple.Fields) Config(org.apache.storm.Config) TransactionalTopologyBuilder(org.apache.storm.transactional.TransactionalTopologyBuilder) LocalTopology(org.apache.storm.LocalCluster.LocalTopology)

Example 19 with LocalCluster

use of org.apache.storm.LocalCluster in project storm by apache.

the class TransactionalWords method main.

public static void main(String[] args) throws Exception {
    MemoryTransactionalSpout spout = new MemoryTransactionalSpout(DATA, new Fields("word"), PARTITION_TAKE_PER_BATCH);
    TransactionalTopologyBuilder builder = new TransactionalTopologyBuilder("top-n-words", "spout", spout, 2);
    builder.setBolt("count", new KeyedCountUpdater(), 5).fieldsGrouping("spout", new Fields("word"));
    builder.setBolt("bucketize", new Bucketize()).noneGrouping("count");
    builder.setBolt("buckets", new BucketCountUpdater(), 5).fieldsGrouping("bucketize", new Fields("bucket"));
    Config config = new Config();
    config.setDebug(true);
    config.setMaxSpoutPending(3);
    try (LocalCluster cluster = new LocalCluster();
        LocalTopology topo = cluster.submitTopology("top-n-topology", config, builder.buildTopology())) {
        Thread.sleep(3000);
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) MemoryTransactionalSpout(org.apache.storm.testing.MemoryTransactionalSpout) Fields(org.apache.storm.tuple.Fields) Config(org.apache.storm.Config) TransactionalTopologyBuilder(org.apache.storm.transactional.TransactionalTopologyBuilder) LocalTopology(org.apache.storm.LocalCluster.LocalTopology)

Example 20 with LocalCluster

use of org.apache.storm.LocalCluster 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);
    if (args != null && args.length > 0) {
        conf.setNumWorkers(3);
        StormSubmitter.submitTopologyWithProgressBar(args[0], conf, builder.createTopology());
    } else {
        conf.setMaxTaskParallelism(3);
        try (LocalCluster cluster = new LocalCluster();
            LocalTopology topo = cluster.submitTopology("word-count", conf, builder.createTopology())) {
            Thread.sleep(10000);
        }
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) Fields(org.apache.storm.tuple.Fields) Config(org.apache.storm.Config) LocalTopology(org.apache.storm.LocalCluster.LocalTopology)

Aggregations

LocalCluster (org.apache.storm.LocalCluster)79 Config (org.apache.storm.Config)71 LocalTopology (org.apache.storm.LocalCluster.LocalTopology)52 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)28 Fields (org.apache.storm.tuple.Fields)22 Map (java.util.Map)14 StreamBuilder (org.apache.storm.streams.StreamBuilder)9 HashMap (java.util.HashMap)7 RandomIntegerSpout (org.apache.storm.starter.spout.RandomIntegerSpout)7 LocalDRPC (org.apache.storm.LocalDRPC)6 JedisPoolConfig (org.apache.storm.redis.common.config.JedisPoolConfig)6 TestWordSpout (org.apache.storm.testing.TestWordSpout)5 FileInputStream (java.io.FileInputStream)4 InputStream (java.io.InputStream)4 StormSubmitter (org.apache.storm.StormSubmitter)4 StormTopology (org.apache.storm.generated.StormTopology)4 ValueMapper (org.apache.storm.streams.operations.mappers.ValueMapper)4 TopologyContext (org.apache.storm.task.TopologyContext)4 Utils (org.apache.storm.utils.Utils)4 Yaml (org.yaml.snakeyaml.Yaml)4