Search in sources :

Example 1 with SimpleMongoLookupMapper

use of org.apache.storm.mongodb.common.mapper.SimpleMongoLookupMapper in project storm by apache.

the class LookupWordCount method main.

public static void main(String[] args) throws Exception {
    String url = TEST_MONGODB_URL;
    String collectionName = TEST_MONGODB_COLLECTION_NAME;
    if (args.length >= 2) {
        url = args[0];
        collectionName = args[1];
    }
    WordSpout spout = new WordSpout();
    TotalWordCounter totalBolt = new TotalWordCounter();
    MongoLookupMapper mapper = new SimpleMongoLookupMapper().withFields("word", "count");
    QueryFilterCreator filterCreator = new SimpleQueryFilterCreator().withField("word");
    MongoLookupBolt lookupBolt = new MongoLookupBolt(url, collectionName, filterCreator, mapper);
    // wordspout -> lookupbolt -> totalCountBolt
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout(WORD_SPOUT, spout, 1);
    builder.setBolt(LOOKUP_BOLT, lookupBolt, 1).shuffleGrouping(WORD_SPOUT);
    builder.setBolt(TOTAL_COUNT_BOLT, totalBolt, 1).fieldsGrouping(LOOKUP_BOLT, new Fields("word"));
    String topoName = "test";
    if (args.length == 3) {
        topoName = args[2];
    } else if (args.length > 3) {
        System.out.println("Usage: LookupWordCount <mongodb url> <mongodb collection> [topology name]");
        return;
    }
    Config config = new Config();
    StormSubmitter.submitTopology(topoName, config, builder.createTopology());
}
Also used : MongoLookupBolt(org.apache.storm.mongodb.bolt.MongoLookupBolt) Fields(org.apache.storm.tuple.Fields) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Config(org.apache.storm.Config) MongoLookupMapper(org.apache.storm.mongodb.common.mapper.MongoLookupMapper) SimpleMongoLookupMapper(org.apache.storm.mongodb.common.mapper.SimpleMongoLookupMapper) SimpleQueryFilterCreator(org.apache.storm.mongodb.common.SimpleQueryFilterCreator) SimpleQueryFilterCreator(org.apache.storm.mongodb.common.SimpleQueryFilterCreator) QueryFilterCreator(org.apache.storm.mongodb.common.QueryFilterCreator) SimpleMongoLookupMapper(org.apache.storm.mongodb.common.mapper.SimpleMongoLookupMapper)

Aggregations

Config (org.apache.storm.Config)1 MongoLookupBolt (org.apache.storm.mongodb.bolt.MongoLookupBolt)1 QueryFilterCreator (org.apache.storm.mongodb.common.QueryFilterCreator)1 SimpleQueryFilterCreator (org.apache.storm.mongodb.common.SimpleQueryFilterCreator)1 MongoLookupMapper (org.apache.storm.mongodb.common.mapper.MongoLookupMapper)1 SimpleMongoLookupMapper (org.apache.storm.mongodb.common.mapper.SimpleMongoLookupMapper)1 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)1 Fields (org.apache.storm.tuple.Fields)1