Search in sources :

Example 6 with PrinterBolt

use of org.apache.storm.starter.bolt.PrinterBolt 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)

Example 7 with PrinterBolt

use of org.apache.storm.starter.bolt.PrinterBolt 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 8 with PrinterBolt

use of org.apache.storm.starter.bolt.PrinterBolt 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");
    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) Count(org.apache.storm.topology.base.BaseWindowedBolt.Count) PrinterBolt(org.apache.storm.starter.bolt.PrinterBolt) LocalTopology(org.apache.storm.LocalCluster.LocalTopology)

Example 9 with PrinterBolt

use of org.apache.storm.starter.bolt.PrinterBolt in project flink by apache.

the class SingleJoinExample method main.

public static void main(String[] args) throws Exception {
    final FeederSpout genderSpout = new FeederSpout(new Fields("id", "gender", "hobbies"));
    final FeederSpout ageSpout = new FeederSpout(new Fields("id", "age"));
    Config conf = new Config();
    TopologyBuilder builder = new TopologyBuilder();
    //  only required to stabilize integration test
    conf.put(FlinkLocalCluster.SUBMIT_BLOCKING, true);
    final NullTerminatingSpout finalGenderSpout = new NullTerminatingSpout(genderSpout);
    final NullTerminatingSpout finalAgeSpout = new NullTerminatingSpout(ageSpout);
    builder.setSpout("gender", finalGenderSpout);
    builder.setSpout("age", finalAgeSpout);
    builder.setBolt("join", new SingleJoinBolt(new Fields("gender", "age"))).fieldsGrouping("gender", new Fields("id")).fieldsGrouping("age", new Fields("id"));
    // emit result
    if (args.length > 0) {
        // read the text file from given input path
        builder.setBolt("fileOutput", new BoltFileSink(args[0], new TupleOutputFormatter())).shuffleGrouping("join");
    } else {
        builder.setBolt("print", new PrinterBolt()).shuffleGrouping("join");
    }
    String[] hobbies = new String[] { "reading", "biking", "travelling", "watching tv" };
    for (int i = 0; i < 10; i++) {
        String gender;
        if (i % 2 == 0) {
            gender = "male";
        } else {
            gender = "female";
        }
        genderSpout.feed(new Values(i, gender, hobbies[i % hobbies.length]));
    }
    for (int i = 9; i >= 0; i--) {
        ageSpout.feed(new Values(i, i + 20));
    }
    final FlinkLocalCluster cluster = FlinkLocalCluster.getLocalCluster();
    cluster.submitTopology("joinTopology", conf, FlinkTopology.createTopology(builder));
    cluster.shutdown();
}
Also used : TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Config(org.apache.storm.Config) TupleOutputFormatter(org.apache.flink.storm.util.TupleOutputFormatter) Values(org.apache.storm.tuple.Values) NullTerminatingSpout(org.apache.flink.storm.util.NullTerminatingSpout) BoltFileSink(org.apache.flink.storm.util.BoltFileSink) Fields(org.apache.storm.tuple.Fields) FlinkLocalCluster(org.apache.flink.storm.api.FlinkLocalCluster) SingleJoinBolt(org.apache.storm.starter.bolt.SingleJoinBolt) FeederSpout(org.apache.storm.testing.FeederSpout) PrinterBolt(org.apache.storm.starter.bolt.PrinterBolt)

Aggregations

PrinterBolt (org.apache.storm.starter.bolt.PrinterBolt)9 Config (org.apache.storm.Config)7 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)7 RandomIntegerSpout (org.apache.storm.starter.spout.RandomIntegerSpout)6 SlidingWindowSumBolt (org.apache.storm.starter.bolt.SlidingWindowSumBolt)4 TopologyBuilder (backtype.storm.topology.TopologyBuilder)2 JStormHelper (com.alibaba.starter.utils.JStormHelper)2 FlinkLocalCluster (org.apache.flink.storm.api.FlinkLocalCluster)2 FeederSpout (org.apache.storm.testing.FeederSpout)2 BaseWindowedBolt (org.apache.storm.topology.base.BaseWindowedBolt)2 Count (org.apache.storm.topology.base.BaseWindowedBolt.Count)2 Fields (org.apache.storm.tuple.Fields)2 BaseWindowedBolt (backtype.storm.topology.base.BaseWindowedBolt)1 Count (backtype.storm.topology.base.BaseWindowedBolt.Count)1 Duration (backtype.storm.topology.base.BaseWindowedBolt.Duration)1 BoltFileSink (org.apache.flink.storm.util.BoltFileSink)1 NullTerminatingSpout (org.apache.flink.storm.util.NullTerminatingSpout)1 TupleOutputFormatter (org.apache.flink.storm.util.TupleOutputFormatter)1 LocalCluster (org.apache.storm.LocalCluster)1 LocalTopology (org.apache.storm.LocalCluster.LocalTopology)1