storm 示例demo

时间:2021-01-25 04:22:22
【文件属性】:

文件名称:storm 示例demo

文件大小:13KB

文件格式:ZIP

更新时间:2021-01-25 04:22:22

storm 流处理 大数据

简单的storm入门示例,从0到1让你清楚的理解storm.下面是代码示例: import backtype.storm.topology.BasicOutputCollector; import backtype.storm.topology.OutputFieldsDeclarer; import backtype.storm.topology.base.BaseBasicBolt; import backtype.storm.tuple.Fields; import backtype.storm.tuple.Tuple; import backtype.storm.tuple.Values; public class WordNormalizer extends BaseBasicBolt { public void cleanup() {} /** * The bolt will receive the line from the * words file and process it to Normalize this line * * The normalize will be put the words in lower case * and split the line to get all words in this */ public void execute(Tuple input, BasicOutputCollector collector) { String sentence = input.getString(0); String[] words = sentence.split(" "); for(String word : words){ word = word.trim(); if(!word.isEmpty()){ word = word.toLowerCase(); collector.emit(new Values(word)); } } } /** * The bolt will only emit the field "word" */ public void declareOutputFields(OutputFieldsDeclarer declarer) { declarer.declare(new Fields("word")); } }


【文件预览】:
storm-book-examples-ch02-getting_started-8e42636
----.gitignore(20B)
----.project(716B)
----pom.xml(1KB)
----target()
--------classes()
----.settings()
--------org.eclipse.jdt.core.prefs(268B)
--------org.maven.ide.eclipse.prefs(262B)
----src()
--------main()
----pom.html(14KB)

网友评论