use of org.apache.storm.streams.StreamState in project storm by apache.
the class StateQueryExample method main.
public static void main(String[] args) throws Exception {
StreamBuilder builder = new StreamBuilder();
StreamState<String, Long> ss = builder.newStream(new TestWordSpout(), new ValueMapper<String>(0), 2).mapToPair(w -> Pair.of(w, 1)).updateStateByKey(0L, (count, val) -> count + 1);
/*
* A stream of words emitted by the QuerySpout is used as
* the keys to query the state.
*/
builder.newStream(new QuerySpout(), new ValueMapper<String>(0)).stateQuery(ss).print();
Config config = new Config();
// use redis based state store for persistence
config.put(Config.TOPOLOGY_STATE_PROVIDER, "org.apache.storm.redis.state.RedisKeyValueStateProvider");
if (args.length > 0) {
config.setNumWorkers(1);
StormSubmitter.submitTopologyWithProgressBar(args[0], config, builder.build());
} else {
try (LocalCluster cluster = new LocalCluster();
LocalCluster.LocalTopology topo = cluster.submitTopology("test", config, builder.build())) {
Utils.sleep(60_000);
}
}
}
Aggregations