Apache Storm Component Guide
Also available as:
PDF
loading table of contents...

Sample Trident Application with Windowing

Here is an example that uses HBaseWindowStoreFactory for windowing:

// define arguments
Map<String, Object> config = new HashMap<>();
String tableName = "window-state";
byte[] columnFamily = “cf”.getBytes(“UTF-8”);
byte[] columnQualifier = “tuples”.getBytes(“UTF-8”);

// window-state table should already be created with cf:tuples column
    HBaseWindowsStoreFactory windowStoreFactory = new HBaseWindowsStoreFactory(config, tablename, columnFamily, columnQualifier);

    FixedBatchSpout spout = new FixedBatchSpout(new Fields("sentence"), 3, new Values("the cow jumped over the moon"),
            new Values("the man went to the store and bought some candy"), new Values("four score and seven years ago"),
            new Values("how many apples can you eat"), new Values("to be or not to be the person"));

    spout.setCycle(true);

    TridentTopology topology = new TridentTopology();

    Stream stream = topology.newStream("spout1", spout).parallelismHint(16).each(new Fields("sentence"),
            new Split(), new Fields("word"))
            .tumblingWindow(1000, windowStoreFactory, new Fields("word"), new CountAsAggregator(), new Fields("count"))
            .peek(new Consumer() {
                @Override
                public void accept(TridentTuple input) {
                    LOG.info("Received tuple: [{}]", input);
                }
            });
    StormTopology stormTopology =  topology.build();

For additional examples that use Trident windowing APIs, see TridentHBaseWindowingStoreTopology and TridentWindowingInmemoryStoreTopology.