Search in sources :

Example 1 with MongoStateFactory

use of org.apache.storm.mongodb.trident.state.MongoStateFactory in project storm by apache.

the class WordCountTrident method buildTopology.

public static StormTopology buildTopology(String url, String collectionName) {
    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);
    MongoMapper mapper = new SimpleMongoMapper().withFields("word", "count");
    MongoState.Options options = new MongoState.Options().withUrl(url).withCollectionName(collectionName).withMapper(mapper);
    StateFactory factory = new MongoStateFactory(options);
    TridentTopology topology = new TridentTopology();
    Stream stream = topology.newStream("spout1", spout);
    stream.partitionPersist(factory, fields, new MongoStateUpdater(), new Fields());
    TridentState state = topology.newStaticState(factory);
    stream = stream.stateQuery(state, new Fields("word"), new MongoStateQuery(), new Fields("columnName", "columnValue"));
    stream.each(new Fields("word", "columnValue"), new PrintFunction(), new Fields());
    return topology.build();
}
Also used : MongoState(org.apache.storm.mongodb.trident.state.MongoState) TridentState(org.apache.storm.trident.TridentState) Values(org.apache.storm.tuple.Values) FixedBatchSpout(org.apache.storm.trident.testing.FixedBatchSpout) Fields(org.apache.storm.tuple.Fields) SimpleMongoMapper(org.apache.storm.mongodb.common.mapper.SimpleMongoMapper) MongoMapper(org.apache.storm.mongodb.common.mapper.MongoMapper) StateFactory(org.apache.storm.trident.state.StateFactory) MongoStateFactory(org.apache.storm.mongodb.trident.state.MongoStateFactory) TridentTopology(org.apache.storm.trident.TridentTopology) MongoStateFactory(org.apache.storm.mongodb.trident.state.MongoStateFactory) Stream(org.apache.storm.trident.Stream) SimpleMongoMapper(org.apache.storm.mongodb.common.mapper.SimpleMongoMapper) MongoStateUpdater(org.apache.storm.mongodb.trident.state.MongoStateUpdater) MongoStateQuery(org.apache.storm.mongodb.trident.state.MongoStateQuery)

Aggregations

MongoMapper (org.apache.storm.mongodb.common.mapper.MongoMapper)1 SimpleMongoMapper (org.apache.storm.mongodb.common.mapper.SimpleMongoMapper)1 MongoState (org.apache.storm.mongodb.trident.state.MongoState)1 MongoStateFactory (org.apache.storm.mongodb.trident.state.MongoStateFactory)1 MongoStateQuery (org.apache.storm.mongodb.trident.state.MongoStateQuery)1 MongoStateUpdater (org.apache.storm.mongodb.trident.state.MongoStateUpdater)1 Stream (org.apache.storm.trident.Stream)1 TridentState (org.apache.storm.trident.TridentState)1 TridentTopology (org.apache.storm.trident.TridentTopology)1 StateFactory (org.apache.storm.trident.state.StateFactory)1 FixedBatchSpout (org.apache.storm.trident.testing.FixedBatchSpout)1 Fields (org.apache.storm.tuple.Fields)1 Values (org.apache.storm.tuple.Values)1