MAPREDUCE服务 MRS-创建Storm Spout:代码样例
时间:2025-05-27 16:38:07
代码样例
下面代码片段在com.huawei.storm.example.common包的“RandomSentenceSpout”类的“nextTuple”方法中,作用在于将收到的字符串拆分成单词。
/** * {@inheritDoc} */ @Override public void nextTuple() { Utils.sleep(100); String[] sentences = new String[] {"the cow jumped over the moon", "an apple a day keeps the doctor away", "four score and seven years ago", "snow white and the seven dwarfs", "i am at two with nature"}; String sentence = sentences[random.nextInt(sentences.length)]; collector.emit(new Values(sentence)); }
support.huaweicloud.com/devg3-mrs/mrs_07_420013.html