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