use of org.apache.storm.redis.bolt.RedisStoreBolt in project storm by apache.
the class WordCountToBolt method main.
public static void main(String[] args) throws Exception {
StreamBuilder builder = new StreamBuilder();
// Redis config parameters for the RedisStoreBolt
JedisPoolConfig poolConfig = new JedisPoolConfig.Builder().setHost("127.0.0.1").setPort(6379).build();
// Storm tuple to redis key-value mapper
RedisStoreMapper storeMapper = new WordCountStoreMapper();
// The redis bolt (sink)
IRichBolt redisStoreBolt = new RedisStoreBolt(poolConfig, storeMapper);
// A stream of words
builder.newStream(new TestWordSpout(), new ValueMapper<String>(0)).mapToPair(w -> Pair.of(w, 1)).countByKey().to(redisStoreBolt);
Config config = new Config();
String topoName = "test";
if (args.length > 0) {
topoName = args[0];
}
config.setNumWorkers(1);
StormSubmitter.submitTopologyWithProgressBar(topoName, config, builder.build());
}
use of org.apache.storm.redis.bolt.RedisStoreBolt in project storm by apache.
the class PersistentWordCount method main.
public static void main(String[] args) throws Exception {
String host = TEST_REDIS_HOST;
int port = TEST_REDIS_PORT;
if (args.length >= 2) {
host = args[0];
port = Integer.parseInt(args[1]);
}
JedisPoolConfig poolConfig = new JedisPoolConfig.Builder().setHost(host).setPort(port).build();
WordSpout spout = new WordSpout();
WordCounter bolt = new WordCounter();
RedisStoreMapper storeMapper = setupStoreMapper();
RedisStoreBolt storeBolt = new RedisStoreBolt(poolConfig, storeMapper);
// wordSpout ==> countBolt ==> RedisBolt
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout(WORD_SPOUT, spout, 1);
builder.setBolt(COUNT_BOLT, bolt, 1).fieldsGrouping(WORD_SPOUT, new Fields("word"));
builder.setBolt(STORE_BOLT, storeBolt, 1).shuffleGrouping(COUNT_BOLT);
String topoName = "test";
if (args.length == 3) {
topoName = args[2];
} else if (args.length > 3) {
System.out.println("Usage: PersistentWordCount <redis host> <redis port> (topology name)");
return;
}
Config config = new Config();
StormSubmitter.submitTopology(topoName, config, builder.createTopology());
}
Aggregations