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();
}
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);
}
}
Aggregations