Search in sources :

Example 1 with MongoLookupMapper

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

the class LookupWordCount method main.

public static void main(String[] args) throws Exception {
    Config config = new Config();
    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"));
    if (args.length == 2) {
        LocalCluster cluster = new LocalCluster();
        cluster.submitTopology("test", config, builder.createTopology());
        Thread.sleep(30000);
        cluster.killTopology("test");
        cluster.shutdown();
        System.exit(0);
    } else if (args.length == 3) {
        StormSubmitter.submitTopology(args[2], config, builder.createTopology());
    } else {
        System.out.println("Usage: LookupWordCount <mongodb url> <mongodb collection> [topology name]");
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) 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 LocalCluster (org.apache.storm.LocalCluster)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