我是Apache Storm的新手。我通过Toppology直接分组示例。 我的执行方法:
public void execute(Tuple input) {
String sentence = input.getString(0);
String[] words = sentence.split(" ");
for (String word : words) {
word = word.trim();
if (!word.isEmpty()) {
word = word.toLowerCase();
// Emit the word
List a = new ArrayList();
a.add(input);
collector.emitDirect(getWordCountIndex(word),new Values(word));
}
}
// Acknowledge the tuple
collector.ack(input);
}
public Integer getWordCountIndex(String word) {
word = word.trim().toUpperCase();
if(word.isEmpty())
return 0;
else{
System.out.println(word +"------"+Character.getNumericValue(word.charAt(0)) % 13);
return Character.getNumericValue(word.charAt(0)) % 13;
}
}
我观察到的是getWordCountIndex()值,如果超过10或0,它不会被计数器螺栓计数。但是,execute会对组元组进行分组,以便所有以相同字母开头的单词将被同一个螺栓接收。
有人可以解释一下这里发生了什么。我检查文档的帮助不大。
谢谢, 阿米特
答案 0 :(得分:0)
引自https://storm.apache.org/documentation/Concepts.html
直接分组:这是一种特殊的分组。流分组 这种方式意味着元组的生产者决定了哪个任务 消费者将获得这个元组。直接分组只能是 在已声明为直接流的流上声明。元组 发射到直接流必须使用其中一个发射 [emitDirect](/的Javadoc / apidocs / backtype /风暴/任务/ OutputCollector.html#emitDirect(INT, int,java.util.List)方法。一个螺栓可以得到它的任务ID 消费者使用提供的TopologyContext或保留 跟踪OutputCollector中的emit方法的输出(其中 返回元组被发送到的任务ID。
所以Character.getNumericValue(word.charAt(0)) % 13
意味着你需要有13个单词计数螺栓任务。否则数据将不被接受。我的猜测是你正在使用10个任务来完成螺栓。