Search in sources :

Example 11 with FixedBatchSpout

use of org.apache.storm.trident.testing.FixedBatchSpout in project storm by apache.

the class TridentMapExample method buildTopology.

public static StormTopology buildTopology(LocalDRPC drpc) {
    FixedBatchSpout spout = new FixedBatchSpout(new Fields("word"), 3, new Values("the cow jumped over the moon"), new Values("the man went to the store and bought some candy"), new Values("four score and seven years ago"), new Values("how many apples can you eat"), new Values("to be or not to be the person"));
    spout.setCycle(true);
    TridentTopology topology = new TridentTopology();
    TridentState wordCounts = topology.newStream("spout1", spout).parallelismHint(16).flatMap(split).map(toUpper, new Fields("uppercased")).filter(theFilter).peek(new Consumer() {

        @Override
        public void accept(TridentTuple input) {
            System.out.println(input.getString(0));
        }
    }).groupBy(new Fields("uppercased")).persistentAggregate(new MemoryMapState.Factory(), new Count(), new Fields("count")).parallelismHint(16);
    topology.newDRPCStream("words", drpc).flatMap(split, new Fields("word")).groupBy(new Fields("word")).stateQuery(wordCounts, new Fields("word"), new MapGet(), new Fields("count")).filter(new FilterNull()).aggregate(new Fields("count"), new Sum(), new Fields("sum"));
    return topology.build();
}
Also used : FixedBatchSpout(org.apache.storm.trident.testing.FixedBatchSpout) FilterNull(org.apache.storm.trident.operation.builtin.FilterNull) Fields(org.apache.storm.tuple.Fields) Consumer(org.apache.storm.trident.operation.Consumer) TridentTopology(org.apache.storm.trident.TridentTopology) TridentState(org.apache.storm.trident.TridentState) Values(org.apache.storm.tuple.Values) MapGet(org.apache.storm.trident.operation.builtin.MapGet) Sum(org.apache.storm.trident.operation.builtin.Sum) Count(org.apache.storm.trident.operation.builtin.Count) TridentTuple(org.apache.storm.trident.tuple.TridentTuple)

Example 12 with FixedBatchSpout

use of org.apache.storm.trident.testing.FixedBatchSpout in project storm by apache.

the class TridentKafkaTopology method buildTopology.

private static StormTopology buildTopology(String brokerConnectionString) {
    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);
    TridentTopology topology = new TridentTopology();
    Stream stream = topology.newStream("spout1", spout);
    Properties props = new Properties();
    props.put("bootstrap.servers", brokerConnectionString);
    props.put("acks", "1");
    props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
    props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
    TridentKafkaStateFactory stateFactory = new TridentKafkaStateFactory().withProducerProperties(props).withKafkaTopicSelector(new DefaultTopicSelector("test")).withTridentTupleToKafkaMapper(new FieldNameBasedTupleToKafkaMapper("word", "count"));
    stream.partitionPersist(stateFactory, fields, new TridentKafkaUpdater(), new Fields());
    return topology.build();
}
Also used : FixedBatchSpout(org.apache.storm.trident.testing.FixedBatchSpout) Fields(org.apache.storm.tuple.Fields) TridentTopology(org.apache.storm.trident.TridentTopology) Values(org.apache.storm.tuple.Values) Stream(org.apache.storm.trident.Stream) DefaultTopicSelector(org.apache.storm.kafka.trident.selector.DefaultTopicSelector) Properties(java.util.Properties) FieldNameBasedTupleToKafkaMapper(org.apache.storm.kafka.trident.mapper.FieldNameBasedTupleToKafkaMapper)

Example 13 with FixedBatchSpout

use of org.apache.storm.trident.testing.FixedBatchSpout in project storm by apache.

the class WordCountTrident method buildTopology.

public static StormTopology buildTopology(String hbaseRoot) {
    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);
    TridentHBaseMapper tridentHBaseMapper = new SimpleTridentHBaseMapper().withColumnFamily("cf").withColumnFields(new Fields("word")).withCounterFields(new Fields("count")).withRowKeyField("word");
    HBaseValueMapper rowToStormValueMapper = new WordCountValueMapper();
    HBaseProjectionCriteria projectionCriteria = new HBaseProjectionCriteria();
    projectionCriteria.addColumn(new HBaseProjectionCriteria.ColumnMetaData("cf", "count"));
    HBaseState.Options options = new HBaseState.Options().withConfigKey(hbaseRoot).withDurability(Durability.SYNC_WAL).withMapper(tridentHBaseMapper).withProjectionCriteria(projectionCriteria).withRowToStormValueMapper(rowToStormValueMapper).withTableName("WordCount");
    StateFactory factory = new HBaseStateFactory(options);
    TridentTopology topology = new TridentTopology();
    Stream stream = topology.newStream("spout1", spout);
    stream.partitionPersist(factory, fields, new HBaseUpdater(), new Fields());
    TridentState state = topology.newStaticState(factory);
    stream = stream.stateQuery(state, new Fields("word"), new HBaseQuery(), new Fields("columnName", "columnValue"));
    stream.each(new Fields("word", "columnValue"), new PrintFunction(), new Fields());
    return topology.build();
}
Also used : HBaseUpdater(org.apache.storm.hbase.trident.state.HBaseUpdater) TridentState(org.apache.storm.trident.TridentState) Values(org.apache.storm.tuple.Values) HBaseProjectionCriteria(org.apache.storm.hbase.bolt.mapper.HBaseProjectionCriteria) WordCountValueMapper(org.apache.storm.hbase.topology.WordCountValueMapper) HBaseValueMapper(org.apache.storm.hbase.bolt.mapper.HBaseValueMapper) HBaseStateFactory(org.apache.storm.hbase.trident.state.HBaseStateFactory) FixedBatchSpout(org.apache.storm.trident.testing.FixedBatchSpout) Fields(org.apache.storm.tuple.Fields) SimpleTridentHBaseMapper(org.apache.storm.hbase.trident.mapper.SimpleTridentHBaseMapper) StateFactory(org.apache.storm.trident.state.StateFactory) HBaseStateFactory(org.apache.storm.hbase.trident.state.HBaseStateFactory) HBaseState(org.apache.storm.hbase.trident.state.HBaseState) TridentTopology(org.apache.storm.trident.TridentTopology) Stream(org.apache.storm.trident.Stream) SimpleTridentHBaseMapper(org.apache.storm.hbase.trident.mapper.SimpleTridentHBaseMapper) TridentHBaseMapper(org.apache.storm.hbase.trident.mapper.TridentHBaseMapper) HBaseQuery(org.apache.storm.hbase.trident.state.HBaseQuery)

Example 14 with FixedBatchSpout

use of org.apache.storm.trident.testing.FixedBatchSpout 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 15 with FixedBatchSpout

use of org.apache.storm.trident.testing.FixedBatchSpout 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

FixedBatchSpout (org.apache.storm.trident.testing.FixedBatchSpout)20 Fields (org.apache.storm.tuple.Fields)20 TridentTopology (org.apache.storm.trident.TridentTopology)19 Values (org.apache.storm.tuple.Values)18 Stream (org.apache.storm.trident.Stream)13 TridentState (org.apache.storm.trident.TridentState)12 MapGet (org.apache.storm.trident.operation.builtin.MapGet)8 Count (org.apache.storm.trident.operation.builtin.Count)7 Sum (org.apache.storm.trident.operation.builtin.Sum)7 StateFactory (org.apache.storm.trident.state.StateFactory)6 FilterNull (org.apache.storm.trident.operation.builtin.FilterNull)5 Consumer (org.apache.storm.trident.operation.Consumer)4 Split (org.apache.storm.trident.testing.Split)4 TridentTuple (org.apache.storm.trident.tuple.TridentTuple)4 InetSocketAddress (java.net.InetSocketAddress)2 HashSet (java.util.HashSet)2 Properties (java.util.Properties)2 MongoMapper (org.apache.storm.mongodb.common.mapper.MongoMapper)2 SimpleMongoMapper (org.apache.storm.mongodb.common.mapper.SimpleMongoMapper)2 JedisClusterConfig (org.apache.storm.redis.common.config.JedisClusterConfig)2