我们可以在Kafka java client-0.8.0版本中设置消费偏移量(抱歉已过时)。我在最新版本中发现了这个,但我希望它在0.8.0版本中
到目前为止的代码:
Map<String, Integer> topicCountMap = new HashMap<String, Integer>();
topicCountMap.put(topic, new Integer(1));
Map<String, List<KafkaStream<byte[], byte[]>>> consumerMap = consumer.createMessageStreams(topicCountMap);
KafkaStream<byte[], byte[]> stream = consumerMap.get(topic).get(0);
ConsumerIterator<byte[], byte[]> it = stream.iterator();
while(it.hasNext()){
String consumerMessage = new String(it.next().message());
}