use of org.apache.storm.mongodb.bolt.MongoUpdateBolt in project storm by apache.
the class UpdateWordCount 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();
WordCounter bolt = new WordCounter();
MongoUpdateMapper mapper = new SimpleMongoUpdateMapper().withFields("word", "count");
QueryFilterCreator filterCreator = new SimpleQueryFilterCreator().withField("word");
MongoUpdateBolt updateBolt = new MongoUpdateBolt(url, collectionName, filterCreator, mapper);
// if a new document should be inserted if there are no matches to the query filter
// updateBolt.withUpsert(true);
// whether find all documents according to the query filter
// updateBolt.withMany(true);
// wordSpout ==> countBolt ==> MongoUpdateBolt
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout(WORD_SPOUT, spout, 1);
builder.setBolt(COUNT_BOLT, bolt, 1).shuffleGrouping(WORD_SPOUT);
builder.setBolt(UPDATE_BOLT, updateBolt, 1).fieldsGrouping(COUNT_BOLT, new Fields("word"));
String topoName = "test";
if (args.length == 3) {
topoName = args[2];
} else if (args.length > 3) {
System.out.println("Usage: UpdateWordCount <mongodb url> <mongodb collection> [topology name]");
return;
}
Config config = new Config();
StormSubmitter.submitTopology(topoName, config, builder.createTopology());
}
Aggregations