/** * 单词计数 */ public class LocalTridentCount { public static class MyBatchSpout implements IBatchSpout { Fields fields; HashMap<Long, List<List<Object>>> batches = new HashMap<Long, List<List<Object>>>(); public MyBatch…
上代码: public class TridentWordCount { public static class Split extends BaseFunction { @Override public void execute(TridentTuple tuple, TridentCollector collector) { String sentence = tuple.getString(0); for (String word : sentence.split(" ")) {…
例子需求: spout:向后端发送{"sentence":"my dog has fleas"}.一般要连数据源,此处简化写死了. 语句分割bolt(SplitSentenceBolt):订阅spout发送的tuple.每收到一个tuple,bolt会获取"sentence"对应值域的值,然后分割为一个个的单词.最后,每个单词向后发送1个tuple: {"word":"my"} {"word&qu…