Search in sources :

Example 1 with Consumer

use of storm.trident.operation.Consumer in project jstorm by alibaba.

the class TridentWindowingInmemoryStoreTopology method buildTopology.

public static StormTopology buildTopology(WindowsStoreFactory windowStore, WindowConfig windowConfig) throws Exception {
    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")).window(windowConfig, windowStore, new Fields("word"), new CountAsAggregator(), new Fields("count")).peek(new Consumer() {

        @Override
        public void accept(TridentTuple input) {
            LOG.info("Received tuple: [{}]", input);
        }
    });
    return topology.build();
}
Also used : FixedBatchSpout(storm.trident.testing.FixedBatchSpout) Fields(backtype.storm.tuple.Fields) Consumer(storm.trident.operation.Consumer) TridentTopology(storm.trident.TridentTopology) CountAsAggregator(storm.trident.testing.CountAsAggregator) Values(backtype.storm.tuple.Values) Stream(storm.trident.Stream) Split(storm.trident.testing.Split) TridentTuple(storm.trident.tuple.TridentTuple)

Example 2 with Consumer

use of storm.trident.operation.Consumer in project jstorm by alibaba.

the class TridentMapExample method buildTopology.

public static StormTopology buildTopology(LocalDRPC drpc) {
    FixedBatchSpout spout = new FixedBatchSpout(new Fields("word"), 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();
    TridentState wordCounts = topology.newStream("spout1", spout).parallelismHint(16).flatMap(split).map(toUpper).filter(theFilter).peek(new Consumer() {

        @Override
        public void accept(TridentTuple input) {
            System.out.println(input.getString(0));
        }
    }).groupBy(new Fields("word")).persistentAggregate(new MemoryMapState.Factory(), new Count(), new Fields("count")).parallelismHint(16);
    topology.newDRPCStream("words", drpc).flatMap(split).groupBy(new Fields("args")).stateQuery(wordCounts, new Fields("args"), new MapGet(), new Fields("count")).filter(new FilterNull()).aggregate(new Fields("count"), new Sum(), new Fields("sum"));
    return topology.build();
}
Also used : FixedBatchSpout(storm.trident.testing.FixedBatchSpout) FilterNull(storm.trident.operation.builtin.FilterNull) Fields(backtype.storm.tuple.Fields) Consumer(storm.trident.operation.Consumer) TridentTopology(storm.trident.TridentTopology) TridentState(storm.trident.TridentState) Values(backtype.storm.tuple.Values) MapGet(storm.trident.operation.builtin.MapGet) Sum(storm.trident.operation.builtin.Sum) Count(storm.trident.operation.builtin.Count) TridentTuple(storm.trident.tuple.TridentTuple)

Aggregations

Fields (backtype.storm.tuple.Fields)2 Values (backtype.storm.tuple.Values)2 TridentTopology (storm.trident.TridentTopology)2 Consumer (storm.trident.operation.Consumer)2 FixedBatchSpout (storm.trident.testing.FixedBatchSpout)2 TridentTuple (storm.trident.tuple.TridentTuple)2 Stream (storm.trident.Stream)1 TridentState (storm.trident.TridentState)1 Count (storm.trident.operation.builtin.Count)1 FilterNull (storm.trident.operation.builtin.FilterNull)1 MapGet (storm.trident.operation.builtin.MapGet)1 Sum (storm.trident.operation.builtin.Sum)1 CountAsAggregator (storm.trident.testing.CountAsAggregator)1 Split (storm.trident.testing.Split)1