我可以看到制作人将消息放在主题中。 我在同一台机器上有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);
}
}