Search in sources :

Example 1 with RedisFilterMapper

use of org.apache.storm.redis.common.mapper.RedisFilterMapper in project storm by apache.

the class WhitelistWordCount method main.

public static void main(String[] args) throws Exception {
    Config config = new Config();
    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();
    RedisFilterMapper filterMapper = setupWhitelistMapper();
    RedisFilterBolt whitelistBolt = new RedisFilterBolt(poolConfig, filterMapper);
    WordCounter wordCounterBolt = new WordCounter();
    PrintWordTotalCountBolt printBolt = new PrintWordTotalCountBolt();
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout(WORD_SPOUT, spout, 1);
    builder.setBolt(WHITELIST_BOLT, whitelistBolt, 1).shuffleGrouping(WORD_SPOUT);
    builder.setBolt(COUNT_BOLT, wordCounterBolt, 1).fieldsGrouping(WHITELIST_BOLT, new Fields("word"));
    builder.setBolt(PRINT_BOLT, printBolt, 1).shuffleGrouping(COUNT_BOLT);
    if (args.length == 2) {
        try (LocalCluster cluster = new LocalCluster();
            LocalTopology topo = cluster.submitTopology("test", config, builder.createTopology())) {
            Thread.sleep(30000);
        }
        System.exit(0);
    } else if (args.length == 3) {
        StormSubmitter.submitTopology(args[2], config, builder.createTopology());
    } else {
        System.out.println("Usage: WhitelistWordCount <redis host> <redis port> (topology name)");
    }
}
Also used : RedisFilterBolt(org.apache.storm.redis.bolt.RedisFilterBolt) LocalCluster(org.apache.storm.LocalCluster) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Config(org.apache.storm.Config) JedisPoolConfig(org.apache.storm.redis.common.config.JedisPoolConfig) JedisPoolConfig(org.apache.storm.redis.common.config.JedisPoolConfig) LocalTopology(org.apache.storm.LocalCluster.LocalTopology) Fields(org.apache.storm.tuple.Fields) RedisFilterMapper(org.apache.storm.redis.common.mapper.RedisFilterMapper)

Aggregations

Config (org.apache.storm.Config)1 LocalCluster (org.apache.storm.LocalCluster)1 LocalTopology (org.apache.storm.LocalCluster.LocalTopology)1 RedisFilterBolt (org.apache.storm.redis.bolt.RedisFilterBolt)1 JedisPoolConfig (org.apache.storm.redis.common.config.JedisPoolConfig)1 RedisFilterMapper (org.apache.storm.redis.common.mapper.RedisFilterMapper)1 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)1 Fields (org.apache.storm.tuple.Fields)1