Search in sources :

Example 1 with RedisLookupMapper

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

the class LookupWordCount 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();
    RedisLookupMapper lookupMapper = setupLookupMapper();
    RedisLookupBolt lookupBolt = new RedisLookupBolt(poolConfig, lookupMapper);
    PrintWordTotalCountBolt printBolt = new PrintWordTotalCountBolt();
    // wordspout -> lookupbolt
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout(WORD_SPOUT, spout, 1);
    builder.setBolt(LOOKUP_BOLT, lookupBolt, 1).shuffleGrouping(WORD_SPOUT);
    builder.setBolt(PRINT_BOLT, printBolt, 1).shuffleGrouping(LOOKUP_BOLT);
    String topoName = "test";
    if (args.length == 3) {
        topoName = args[2];
    } else if (args.length > 3) {
        System.out.println("Usage: LookupWordCount <redis host> <redis port> (topology name)");
        return;
    }
    Config config = new Config();
    StormSubmitter.submitTopology(topoName, config, builder.createTopology());
}
Also used : RedisLookupBolt(org.apache.storm.redis.bolt.RedisLookupBolt) 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) RedisLookupMapper(org.apache.storm.redis.common.mapper.RedisLookupMapper)

Example 2 with RedisLookupMapper

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

the class WordCountTridentRedis method buildTopology.

public static StormTopology buildTopology(String redisHost, Integer redisPort) {
    Fields fields = new Fields("word", "count");
    FixedBatchSpout spout = new FixedBatchSpout(fields, 4, new Values("storm", 1), new Values("trident", 1), new Values("needs", 1), new Values("javadoc", 1));
    spout.setCycle(true);
    JedisPoolConfig poolConfig = new JedisPoolConfig.Builder().setHost(redisHost).setPort(redisPort).build();
    RedisStoreMapper storeMapper = new WordCountStoreMapper();
    RedisLookupMapper lookupMapper = new WordCountLookupMapper();
    RedisState.Factory factory = new RedisState.Factory(poolConfig);
    TridentTopology topology = new TridentTopology();
    Stream stream = topology.newStream("spout1", spout);
    stream.partitionPersist(factory, fields, new RedisStateUpdater(storeMapper).withExpire(86400000), new Fields());
    TridentState state = topology.newStaticState(factory);
    stream = stream.stateQuery(state, new Fields("word"), new RedisStateQuerier(lookupMapper), new Fields("columnName", "columnValue"));
    stream.each(new Fields("word", "columnValue"), new PrintFunction(), new Fields());
    return topology.build();
}
Also used : TridentState(org.apache.storm.trident.TridentState) RedisStateQuerier(org.apache.storm.redis.trident.state.RedisStateQuerier) Values(org.apache.storm.tuple.Values) JedisPoolConfig(org.apache.storm.redis.common.config.JedisPoolConfig) FixedBatchSpout(org.apache.storm.trident.testing.FixedBatchSpout) Fields(org.apache.storm.tuple.Fields) TridentTopology(org.apache.storm.trident.TridentTopology) RedisStateUpdater(org.apache.storm.redis.trident.state.RedisStateUpdater) RedisState(org.apache.storm.redis.trident.state.RedisState) RedisStoreMapper(org.apache.storm.redis.common.mapper.RedisStoreMapper) Stream(org.apache.storm.trident.Stream) RedisLookupMapper(org.apache.storm.redis.common.mapper.RedisLookupMapper)

Example 3 with RedisLookupMapper

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

the class WordCountTridentRedisCluster method buildTopology.

public static StormTopology buildTopology(String redisHostPort) {
    Fields fields = new Fields("word", "count");
    FixedBatchSpout spout = new FixedBatchSpout(fields, 4, new Values("storm", 1), new Values("trident", 1), new Values("needs", 1), new Values("javadoc", 1));
    spout.setCycle(true);
    Set<InetSocketAddress> nodes = new HashSet<InetSocketAddress>();
    for (String hostPort : redisHostPort.split(",")) {
        String[] hostPortSplit = hostPort.split(":");
        nodes.add(new InetSocketAddress(hostPortSplit[0], Integer.valueOf(hostPortSplit[1])));
    }
    JedisClusterConfig clusterConfig = new JedisClusterConfig.Builder().setNodes(nodes).build();
    RedisStoreMapper storeMapper = new WordCountStoreMapper();
    RedisLookupMapper lookupMapper = new WordCountLookupMapper();
    RedisClusterState.Factory factory = new RedisClusterState.Factory(clusterConfig);
    TridentTopology topology = new TridentTopology();
    Stream stream = topology.newStream("spout1", spout);
    stream.partitionPersist(factory, fields, new RedisClusterStateUpdater(storeMapper).withExpire(86400000), new Fields());
    TridentState state = topology.newStaticState(factory);
    stream = stream.stateQuery(state, new Fields("word"), new RedisClusterStateQuerier(lookupMapper), new Fields("columnName", "columnValue"));
    stream.each(new Fields("word", "columnValue"), new PrintFunction(), new Fields());
    return topology.build();
}
Also used : RedisClusterStateUpdater(org.apache.storm.redis.trident.state.RedisClusterStateUpdater) TridentState(org.apache.storm.trident.TridentState) InetSocketAddress(java.net.InetSocketAddress) JedisClusterConfig(org.apache.storm.redis.common.config.JedisClusterConfig) RedisClusterState(org.apache.storm.redis.trident.state.RedisClusterState) Values(org.apache.storm.tuple.Values) RedisClusterStateQuerier(org.apache.storm.redis.trident.state.RedisClusterStateQuerier) FixedBatchSpout(org.apache.storm.trident.testing.FixedBatchSpout) Fields(org.apache.storm.tuple.Fields) TridentTopology(org.apache.storm.trident.TridentTopology) RedisStoreMapper(org.apache.storm.redis.common.mapper.RedisStoreMapper) Stream(org.apache.storm.trident.Stream) RedisLookupMapper(org.apache.storm.redis.common.mapper.RedisLookupMapper) HashSet(java.util.HashSet)

Aggregations

RedisLookupMapper (org.apache.storm.redis.common.mapper.RedisLookupMapper)3 JedisPoolConfig (org.apache.storm.redis.common.config.JedisPoolConfig)2 RedisStoreMapper (org.apache.storm.redis.common.mapper.RedisStoreMapper)2 Stream (org.apache.storm.trident.Stream)2 TridentState (org.apache.storm.trident.TridentState)2 TridentTopology (org.apache.storm.trident.TridentTopology)2 FixedBatchSpout (org.apache.storm.trident.testing.FixedBatchSpout)2 Fields (org.apache.storm.tuple.Fields)2 Values (org.apache.storm.tuple.Values)2 InetSocketAddress (java.net.InetSocketAddress)1 HashSet (java.util.HashSet)1 Config (org.apache.storm.Config)1 RedisLookupBolt (org.apache.storm.redis.bolt.RedisLookupBolt)1 JedisClusterConfig (org.apache.storm.redis.common.config.JedisClusterConfig)1 RedisClusterState (org.apache.storm.redis.trident.state.RedisClusterState)1 RedisClusterStateQuerier (org.apache.storm.redis.trident.state.RedisClusterStateQuerier)1 RedisClusterStateUpdater (org.apache.storm.redis.trident.state.RedisClusterStateUpdater)1 RedisState (org.apache.storm.redis.trident.state.RedisState)1 RedisStateQuerier (org.apache.storm.redis.trident.state.RedisStateQuerier)1 RedisStateUpdater (org.apache.storm.redis.trident.state.RedisStateUpdater)1