Search in sources :

Example 1 with RedisStoreBolt

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());
}
Also used : IRichBolt(org.apache.storm.topology.IRichBolt) RedisStoreBolt(org.apache.storm.redis.bolt.RedisStoreBolt) ValueMapper(org.apache.storm.streams.operations.mappers.ValueMapper) Config(org.apache.storm.Config) JedisPoolConfig(org.apache.storm.redis.common.config.JedisPoolConfig) TestWordSpout(org.apache.storm.testing.TestWordSpout) RedisStoreMapper(org.apache.storm.redis.common.mapper.RedisStoreMapper) JedisPoolConfig(org.apache.storm.redis.common.config.JedisPoolConfig) StreamBuilder(org.apache.storm.streams.StreamBuilder)

Example 2 with RedisStoreBolt

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());
}
Also used : Fields(org.apache.storm.tuple.Fields) RedisStoreBolt(org.apache.storm.redis.bolt.RedisStoreBolt) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Config(org.apache.storm.Config) JedisPoolConfig(org.apache.storm.redis.common.config.JedisPoolConfig) RedisStoreMapper(org.apache.storm.redis.common.mapper.RedisStoreMapper) JedisPoolConfig(org.apache.storm.redis.common.config.JedisPoolConfig)

Aggregations

Config (org.apache.storm.Config)2 RedisStoreBolt (org.apache.storm.redis.bolt.RedisStoreBolt)2 JedisPoolConfig (org.apache.storm.redis.common.config.JedisPoolConfig)2 RedisStoreMapper (org.apache.storm.redis.common.mapper.RedisStoreMapper)2 StreamBuilder (org.apache.storm.streams.StreamBuilder)1 ValueMapper (org.apache.storm.streams.operations.mappers.ValueMapper)1 TestWordSpout (org.apache.storm.testing.TestWordSpout)1 IRichBolt (org.apache.storm.topology.IRichBolt)1 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)1 Fields (org.apache.storm.tuple.Fields)1