Search in sources :

Example 1 with MemoryTransactionalSpout

use of org.apache.storm.testing.MemoryTransactionalSpout 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 2 with MemoryTransactionalSpout

use of org.apache.storm.testing.MemoryTransactionalSpout 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)

Aggregations

Config (org.apache.storm.Config)2 LocalCluster (org.apache.storm.LocalCluster)2 LocalTopology (org.apache.storm.LocalCluster.LocalTopology)2 MemoryTransactionalSpout (org.apache.storm.testing.MemoryTransactionalSpout)2 TransactionalTopologyBuilder (org.apache.storm.transactional.TransactionalTopologyBuilder)2 Fields (org.apache.storm.tuple.Fields)2