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