KAFKA消费者没有阅读消息。更新offsate.Console消费者正在读取消息

时间:2017-03-21 04:20:21

标签: java apache-kafka kafka-consumer-api

我可以看到制作人将消息放在主题中。 我在同一台机器上有KAFKA和Zookeeper。

      Map<String, List<KafkaStream<byte[], byte[]>>> consumerStreams =   CONSUMERCONNECTOR.createMessageStreams(topicCount);         
      // Get Kafka stream for topic 
      List<KafkaStream<byte[], byte[]>> kStreamList = consumerStreams.get(topic);
      // Iterate stream using ConsumerIterator
      String strMsg = new String();
      if(logger.isDebugEnabled()){
          logger.debug(" \n start reading messages");
      }
      for (final KafkaStream<byte[], byte[]> kStreams : kStreamList) {
          if(logger.isDebugEnabled()){
              logger.debug(" \n in For loop. Size of streamlist: " + kStreamList.size());
          }

             ConsumerIterator<byte[], byte[]> consumerIte = kStreams.iterator();
             if(logger.isDebugEnabled()){
                 logger.debug(" \n got iterator. Size: " + consumerIte.size());
             }
             while (consumerIte.hasNext()){
                 strMsg = new String(consumerIte.next().message());
                 logger.debug("Message consumed from topic    [" + topic + "] : "  + strMsg);
                 addToEventCollection(strMsg);
             }
      }

0 个答案:

没有答案