Search in sources :

Example 71 with LocalCluster

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

the class BranchExample method main.

@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
    StreamBuilder builder = new StreamBuilder();
    Stream<Integer>[] evenAndOdd = builder.newStream(new RandomIntegerSpout(), new ValueMapper<Integer>(0)).branch(x -> (x % 2) == 0, x -> (x % 2) == 1);
    evenAndOdd[0].forEach(x -> LOG.info("EVEN> " + x));
    evenAndOdd[1].forEach(x -> LOG.info("ODD > " + x));
    Config config = new Config();
    if (args.length > 0) {
        config.setNumWorkers(1);
        StormSubmitter.submitTopologyWithProgressBar(args[0], config, builder.build());
    } else {
        try (LocalCluster cluster = new LocalCluster();
            LocalCluster.LocalTopology topo = cluster.submitTopology("test", config, builder.build())) {
            Utils.sleep(60_000);
        }
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) ValueMapper(org.apache.storm.streams.operations.mappers.ValueMapper) Config(org.apache.storm.Config) RandomIntegerSpout(org.apache.storm.starter.spout.RandomIntegerSpout) Stream(org.apache.storm.streams.Stream) StreamBuilder(org.apache.storm.streams.StreamBuilder)

Example 72 with LocalCluster

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

the class GroupByKeyAndWindowExample method main.

public static void main(String[] args) throws Exception {
    StreamBuilder builder = new StreamBuilder();
    // a stream of stock quotes
    builder.newStream(new StockQuotes(), new PairValueMapper<String, Double>(0, 1)).groupByKeyAndWindow(SlidingWindows.of(Count.of(6), Count.of(3))).print();
    // a stream of stock quotes
    builder.newStream(new StockQuotes(), new PairValueMapper<String, Double>(0, 1)).reduceByKeyAndWindow((x, y) -> x > y ? x : y, SlidingWindows.of(Count.of(6), Count.of(3))).print();
    Config config = new Config();
    if (args.length > 0) {
        config.setNumWorkers(1);
        StormSubmitter.submitTopologyWithProgressBar(args[0], config, builder.build());
    } else {
        try (LocalCluster cluster = new LocalCluster();
            LocalCluster.LocalTopology topo = cluster.submitTopology("test", config, builder.build())) {
            Utils.sleep(60_000);
        }
    }
}
Also used : StormSubmitter(org.apache.storm.StormSubmitter) OutputFieldsDeclarer(org.apache.storm.topology.OutputFieldsDeclarer) BaseRichSpout(org.apache.storm.topology.base.BaseRichSpout) PairValueMapper(org.apache.storm.streams.operations.mappers.PairValueMapper) Arrays(java.util.Arrays) PairStream(org.apache.storm.streams.PairStream) StreamBuilder(org.apache.storm.streams.StreamBuilder) TopologyContext(org.apache.storm.task.TopologyContext) Fields(org.apache.storm.tuple.Fields) Utils(org.apache.storm.utils.Utils) Reducer(org.apache.storm.streams.operations.Reducer) LocalCluster(org.apache.storm.LocalCluster) Values(org.apache.storm.tuple.Values) List(java.util.List) SlidingWindows(org.apache.storm.streams.windowing.SlidingWindows) Window(org.apache.storm.streams.windowing.Window) Map(java.util.Map) Count(org.apache.storm.topology.base.BaseWindowedBolt.Count) Config(org.apache.storm.Config) SpoutOutputCollector(org.apache.storm.spout.SpoutOutputCollector) LocalCluster(org.apache.storm.LocalCluster) Config(org.apache.storm.Config) StreamBuilder(org.apache.storm.streams.StreamBuilder)

Example 73 with LocalCluster

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

the class WindowedWordCount method main.

public static void main(String[] args) throws Exception {
    StreamBuilder builder = new StreamBuilder();
    // A stream of random sentences
    builder.newStream(new RandomSentenceSpout(), new ValueMapper<String>(0), 2).window(TumblingWindows.of(Duration.seconds(2))).flatMap(s -> Arrays.asList(s.split(" "))).mapToPair(w -> Pair.of(w, 1)).countByKey().filter(x -> x.getSecond() >= 5).print();
    Config config = new Config();
    if (args.length > 0) {
        config.setNumWorkers(1);
        StormSubmitter.submitTopologyWithProgressBar(args[0], config, builder.build());
    } else {
        try (LocalCluster cluster = new LocalCluster();
            LocalCluster.LocalTopology topo = cluster.submitTopology("test", config, builder.build())) {
            Utils.sleep(60_000);
        }
    }
}
Also used : RandomSentenceSpout(org.apache.storm.starter.spout.RandomSentenceSpout) LocalCluster(org.apache.storm.LocalCluster) StormSubmitter(org.apache.storm.StormSubmitter) Duration(org.apache.storm.topology.base.BaseWindowedBolt.Duration) Arrays(java.util.Arrays) Pair(org.apache.storm.streams.Pair) StreamBuilder(org.apache.storm.streams.StreamBuilder) TumblingWindows(org.apache.storm.streams.windowing.TumblingWindows) ValueMapper(org.apache.storm.streams.operations.mappers.ValueMapper) Config(org.apache.storm.Config) Utils(org.apache.storm.utils.Utils) RandomSentenceSpout(org.apache.storm.starter.spout.RandomSentenceSpout) LocalCluster(org.apache.storm.LocalCluster) Config(org.apache.storm.Config) StreamBuilder(org.apache.storm.streams.StreamBuilder)

Example 74 with LocalCluster

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

the class ManualDRPC method main.

public static void main(String[] args) throws Exception {
    TopologyBuilder builder = new TopologyBuilder();
    try (LocalDRPC drpc = new LocalDRPC();
        LocalCluster cluster = new LocalCluster()) {
        DRPCSpout spout = new DRPCSpout("exclamation", drpc);
        builder.setSpout("drpc", spout);
        builder.setBolt("exclaim", new ExclamationBolt(), 3).shuffleGrouping("drpc");
        builder.setBolt("return", new ReturnResults(), 3).shuffleGrouping("exclaim");
        Config conf = new Config();
        try (LocalTopology topo = cluster.submitTopology("exclaim", conf, builder.createTopology())) {
            System.out.println(drpc.execute("exclamation", "aaa"));
            System.out.println(drpc.execute("exclamation", "bbb"));
        }
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Config(org.apache.storm.Config) LocalDRPC(org.apache.storm.LocalDRPC) ReturnResults(org.apache.storm.drpc.ReturnResults) DRPCSpout(org.apache.storm.drpc.DRPCSpout) LocalTopology(org.apache.storm.LocalCluster.LocalTopology)

Example 75 with LocalCluster

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

the class MultipleLoggerTopology method main.

public static void main(String[] args) throws Exception {
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("word", new TestWordSpout(), 10);
    builder.setBolt("exclaim1", new ExclamationLoggingBolt(), 3).shuffleGrouping("word");
    builder.setBolt("exclaim2", new ExclamationLoggingBolt(), 2).shuffleGrouping("exclaim1");
    Config conf = new Config();
    conf.setDebug(true);
    if (args != null && args.length > 0) {
        conf.setNumWorkers(2);
        StormSubmitter.submitTopologyWithProgressBar(args[0], conf, builder.createTopology());
    } else {
        try (LocalCluster cluster = new LocalCluster();
            LocalTopology topo = cluster.submitTopology("test", conf, builder.createTopology())) {
            Utils.sleep(10000);
        }
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Config(org.apache.storm.Config) TestWordSpout(org.apache.storm.testing.TestWordSpout) LocalTopology(org.apache.storm.LocalCluster.LocalTopology)

Aggregations

LocalCluster (org.apache.storm.LocalCluster)76 Config (org.apache.storm.Config)70 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 RandomIntegerSpout (org.apache.storm.starter.spout.RandomIntegerSpout)7 HashMap (java.util.HashMap)6 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