我是Java新手,并且使用https://cwiki.apache.org/confluence/display/KAFKA/Consumer+Group+Example博客,试图开发嵌入式适配器以接收来自Kafka的流。
这是代码的一部分,它假定使用者是单线程的。

public void run() {
    Map<String, Integer> topicCountMap = new HashMap<String, Integer>();
    topicCountMap.put(topic, new Integer(getNumThreads()));
    Map<String, List<KafkaStream<String, String>>> consumerMap = consumer.createMessageStreams(topicCountMap);
    List<KafkaStream<String, String>> streams = consumerMap.get(topic);

    executor = Executors.newFixedThreadPool(1);

    final KafkaStream<String, String> stream = streams.get(0);
    ConsumerIterator<String, String> it = stream.iterator();
    while (it.hasNext()) {
           // fill the tuple and output the tuple
           fillAndOutputTuple();
           }


我从Eclipse IDE收到关于it.hasNext()的错误:
类文件Iterator包含签名'(I)Lscala / collection / Iterator.GroupedIterator;'在第57位格式错误

(奇怪的是,位置57不像它给出错误那样存在。)

非常感谢任何帮助

最佳答案

将Java代码与用Scala编写的库(如Kafka)混合时,似乎会发生此错误。您能否验证scala-library-x.yz.jar(x.yz是您使用的Kafka构建所需的Scala版本)是否在eclipse项目的“构建路径”中?请参阅https://groups.google.com/forum/#!topic/liftweb/f0IAaqoWyu4

关于java - Kafka简单消费者-在迭代器上出现错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25777178/

10-08 22:28
查看更多