Search in sources :

Example 6 with JedisPoolConfig

use of org.apache.storm.redis.common.config.JedisPoolConfig 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 7 with JedisPoolConfig

use of org.apache.storm.redis.common.config.JedisPoolConfig in project storm by apache.

the class RedisDataSourcesProvider method constructTrident.

@Override
public ISqlTridentDataSource constructTrident(URI uri, String inputFormatClass, String outputFormatClass, Properties props, List<FieldInfo> fields) {
    Preconditions.checkArgument(JedisURIHelper.isValid(uri), "URI is not valid for Redis: " + uri);
    String host = uri.getHost();
    int port = uri.getPort() != -1 ? uri.getPort() : DEFAULT_REDIS_PORT;
    int dbIdx = JedisURIHelper.getDBIndex(uri);
    String password = JedisURIHelper.getPassword(uri);
    int timeout = Integer.parseInt(props.getProperty("redis.timeout", String.valueOf(DEFAULT_TIMEOUT)));
    boolean clusterMode = Boolean.valueOf(props.getProperty("use.redis.cluster", "false"));
    List<String> fieldNames = FieldInfoUtils.getFieldNames(fields);
    IOutputSerializer serializer = SerdeUtils.getSerializer(outputFormatClass, props, fieldNames);
    if (clusterMode) {
        JedisClusterConfig config = new JedisClusterConfig.Builder().setNodes(Collections.singleton(new InetSocketAddress(host, port))).setTimeout(timeout).build();
        return new RedisClusterTridentDataSource(config, props, fields, serializer);
    } else {
        JedisPoolConfig config = new JedisPoolConfig(host, port, timeout, password, dbIdx);
        return new RedisTridentDataSource(config, props, fields, serializer);
    }
}
Also used : IOutputSerializer(org.apache.storm.sql.runtime.IOutputSerializer) InetSocketAddress(java.net.InetSocketAddress) JedisClusterConfig(org.apache.storm.redis.common.config.JedisClusterConfig) JedisPoolConfig(org.apache.storm.redis.common.config.JedisPoolConfig)

Aggregations

JedisPoolConfig (org.apache.storm.redis.common.config.JedisPoolConfig)7 Config (org.apache.storm.Config)4 LocalCluster (org.apache.storm.LocalCluster)4 Fields (org.apache.storm.tuple.Fields)4 LocalTopology (org.apache.storm.LocalCluster.LocalTopology)3 RedisStoreMapper (org.apache.storm.redis.common.mapper.RedisStoreMapper)3 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)3 RedisStoreBolt (org.apache.storm.redis.bolt.RedisStoreBolt)2 JedisClusterConfig (org.apache.storm.redis.common.config.JedisClusterConfig)2 RedisLookupMapper (org.apache.storm.redis.common.mapper.RedisLookupMapper)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 Values (org.apache.storm.tuple.Values)2 InetSocketAddress (java.net.InetSocketAddress)1 RedisFilterBolt (org.apache.storm.redis.bolt.RedisFilterBolt)1 RedisLookupBolt (org.apache.storm.redis.bolt.RedisLookupBolt)1 RedisDataTypeDescription (org.apache.storm.redis.common.mapper.RedisDataTypeDescription)1 RedisFilterMapper (org.apache.storm.redis.common.mapper.RedisFilterMapper)1