简体   繁体   English

Apache Storm发出DirectDirect问题

[英]Apache Storm emitDirect issues

I am new to Apache Storm. 我是Apache Storm的新手。 I was going thru the Toppology direct grouping example. 我正在通过拓扑直接分组示例。 My execute method : 我的执行方法:

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;
        }
    }

what I observed was getWordCountIndex() value if more than 10 or 0 it is not being counted by the counter bolt. 我观察到的是getWordCountIndex()值,如果大于10或0,则不会被固定螺栓计数。 However execute does group tuples so that all words that start with the same letter will be received by the same bolt. 但是execute会对元组进行分组,以便以相同的字母接收以相同字母开头的所有单词。

Can someone please explain what is going on here. 有人可以解释一下这是怎么回事。 I checked the documentation not much help. 我检查了文档没有太大帮助。

Thanks, Amit 谢谢阿米特

referred from https://storm.apache.org/documentation/Concepts.html 参考https://storm.apache.org/documentation/Concepts.html

Direct grouping: This is a special kind of grouping. 直接分组:这是一种特殊的分组。 A stream grouped this way means that the producer of the tuple decides which task of the consumer will receive this tuple. 以这种方式分组的流意味着元组的生产者决定消费者的哪个任务将接收此元组。 Direct groupings can only be declared on streams that have been declared as direct streams. 直接分组只能在已经声明为直接流的流上声明。 Tuples emitted to a direct stream must be emitted using one of the [emitDirect](/javadoc/apidocs/backtype/storm/task/OutputCollector.html#emitDirect(int, int, java.util.List) methods. A bolt can get the task ids of its consumers by either using the provided TopologyContext or by keeping track of the output of the emit method in OutputCollector (which returns the task ids that the tuple was sent to). 发出直接流的元组必须使用[emitDirect](/ javadoc / apidocs / backtype / storm / task / OutputCollector.html#emitDirect(int,int,java.util.List)方法之一发出。通过使用提供的TopologyContext或通过在OutputCollector中跟踪emit方法的输出(返回元组发送到的任务ID)来了解其使用者的任务ID。

So Character.getNumericValue(word.charAt(0)) % 13 means you need to have 13 tasks for word count bolt. 因此Character.getNumericValue(word.charAt(0)) % 13表示您需要执行13个任务来进行字数统计。 otherwise the data will not be accepted. 否则数据将不被接受。 My guess is you are using 10 tasks for the bolt. 我的猜测是您正在执行10个任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM