Search in sources :

Example 1 with RandomIntegerSpout

use of org.apache.storm.starter.spout.RandomIntegerSpout 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 2 with RandomIntegerSpout

use of org.apache.storm.starter.spout.RandomIntegerSpout 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 3 with RandomIntegerSpout

use of org.apache.storm.starter.spout.RandomIntegerSpout in project storm by apache.

the class TypedTupleExample method main.

@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
    StreamBuilder builder = new StreamBuilder();
    /**
         * The spout emits sequences of (Integer, Long, Long). TupleValueMapper can be used to extract fields
         * from the values and produce a stream of typed tuple (Tuple3<Integer, Long, Long> in this case.
         */
    Stream<Tuple3<Integer, Long, Long>> stream = builder.newStream(new RandomIntegerSpout(), TupleValueMappers.of(0, 1, 2));
    PairStream<Long, Integer> pairs = stream.mapToPair(t -> Pair.of(t._2 / 10000, t._1));
    pairs.window(TumblingWindows.of(Count.of(10))).groupByKey().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 : LocalCluster(org.apache.storm.LocalCluster) Config(org.apache.storm.Config) Tuple3(org.apache.storm.streams.tuple.Tuple3) RandomIntegerSpout(org.apache.storm.starter.spout.RandomIntegerSpout) StreamBuilder(org.apache.storm.streams.StreamBuilder)

Example 4 with RandomIntegerSpout

use of org.apache.storm.starter.spout.RandomIntegerSpout in project jstorm by alibaba.

the class SlidingTupleTsTopology method test.

public static void test() {
    String[] className = Thread.currentThread().getStackTrace()[1].getClassName().split("\\.");
    String topologyName = className[className.length - 1];
    try {
        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");
        conf.setDebug(true);
        JStormHelper.runTopology(builder.createTopology(), topologyName, conf, 60, new JStormHelper.CheckAckedFail(conf), isLocal);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Assert.fail("Failed");
    }
}
Also used : JStormHelper(com.alibaba.starter.utils.JStormHelper) TopologyBuilder(backtype.storm.topology.TopologyBuilder) RandomIntegerSpout(org.apache.storm.starter.spout.RandomIntegerSpout) Duration(backtype.storm.topology.base.BaseWindowedBolt.Duration) SlidingWindowSumBolt(org.apache.storm.starter.bolt.SlidingWindowSumBolt) PrinterBolt(org.apache.storm.starter.bolt.PrinterBolt) BaseWindowedBolt(backtype.storm.topology.base.BaseWindowedBolt)

Example 5 with RandomIntegerSpout

use of org.apache.storm.starter.spout.RandomIntegerSpout in project jstorm by alibaba.

the class SlidingWindowTopology method test.

public static void test() {
    String[] className = Thread.currentThread().getStackTrace()[1].getClassName().split("\\.");
    String topologyName = className[className.length - 1];
    try {
        TopologyBuilder builder = new TopologyBuilder();
        builder.setSpout("integer", new RandomIntegerSpout(), 1);
        builder.setBolt("slidingsum", new SlidingWindowSumBolt().withWindow(new Count(30), new Count(10)), 1).shuffleGrouping("integer");
        builder.setBolt("tumblingavg", new TumblingWindowAvgBolt().withTumblingWindow(new Count(3)), 1).shuffleGrouping("slidingsum");
        builder.setBolt("printer", new PrinterBolt(), 1).shuffleGrouping("tumblingavg");
        conf.setDebug(true);
        JStormHelper.runTopology(builder.createTopology(), topologyName, conf, 60, new JStormHelper.CheckAckedFail(conf), isLocal);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.fillInStackTrace();
        Assert.fail("Failed to submit topology");
    }
}
Also used : JStormHelper(com.alibaba.starter.utils.JStormHelper) TopologyBuilder(backtype.storm.topology.TopologyBuilder) RandomIntegerSpout(org.apache.storm.starter.spout.RandomIntegerSpout) Count(backtype.storm.topology.base.BaseWindowedBolt.Count) SlidingWindowSumBolt(org.apache.storm.starter.bolt.SlidingWindowSumBolt) PrinterBolt(org.apache.storm.starter.bolt.PrinterBolt)

Aggregations

RandomIntegerSpout (org.apache.storm.starter.spout.RandomIntegerSpout)9 Config (org.apache.storm.Config)7 LocalCluster (org.apache.storm.LocalCluster)7 PrinterBolt (org.apache.storm.starter.bolt.PrinterBolt)5 LocalTopology (org.apache.storm.LocalCluster.LocalTopology)4 SlidingWindowSumBolt (org.apache.storm.starter.bolt.SlidingWindowSumBolt)4 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)4 StreamBuilder (org.apache.storm.streams.StreamBuilder)3 TopologyBuilder (backtype.storm.topology.TopologyBuilder)2 JStormHelper (com.alibaba.starter.utils.JStormHelper)2 BaseWindowedBolt (backtype.storm.topology.base.BaseWindowedBolt)1 Count (backtype.storm.topology.base.BaseWindowedBolt.Count)1 Duration (backtype.storm.topology.base.BaseWindowedBolt.Duration)1 Stream (org.apache.storm.streams.Stream)1 ValueMapper (org.apache.storm.streams.operations.mappers.ValueMapper)1 Tuple3 (org.apache.storm.streams.tuple.Tuple3)1 BaseWindowedBolt (org.apache.storm.topology.base.BaseWindowedBolt)1 Count (org.apache.storm.topology.base.BaseWindowedBolt.Count)1 Duration (org.apache.storm.topology.base.BaseWindowedBolt.Duration)1