use of org.apache.storm.streams.PairStream in project storm by apache.
the class JoinExample method main.
public static void main(String[] args) throws Exception {
StreamBuilder builder = new StreamBuilder();
// a stream of (number, square) pairs
PairStream<Integer, Integer> squares = builder.newStream(new NumberSpout(x -> x * x), new PairValueMapper<>(0, 1));
// a stream of (number, cube) pairs
PairStream<Integer, Integer> cubes = builder.newStream(new NumberSpout(x -> x * x * x), new PairValueMapper<>(0, 1));
// create a windowed stream of five seconds duration
squares.window(TumblingWindows.of(Duration.seconds(5))).join(cubes).print();
Config config = new Config();
String topoName = JoinExample.class.getName();
if (args.length > 0) {
topoName = args[0];
}
config.setNumWorkers(1);
StormSubmitter.submitTopologyWithProgressBar(topoName, config, builder.build());
}
Aggregations