我使用老卡夫卡消费者0.8V。 的步骤
任何人都可以解释这种行为吗?
消费
public class KafkaMessageListenerThread implements Runnable {
private KafkaStream<byte[], byte[]> stream;
private final KafkaMessageListener baseConsumer;
public KafkaMessageListenerThread(KafkaMessageListener consumer, KafkaStream<byte[], byte[]> stream) {
this.baseConsumer = consumer;
this.stream = stream;
}
public void run() {
ConsumerIterator<byte[], byte[]> itr = stream.iterator();
System.out.println("listens....");
while (itr.hasNext()) {
System.out.println("kafka record : " + itr.next());
byte[] data = itr.next().message();
baseConsumer.receiveData(data);
}
}
}
BaseConsumer
public void start() {
try {
Map<String, Integer> topicCountMap = new HashMap<String, Integer>();
topicCountMap.put(topic, CoreConstants.THREAD_SIZE);
Map<String, List<KafkaStream<byte[], byte[]>>> consumerMap = consumerConnector
.createMessageStreams(topicCountMap);
List<KafkaStream<byte[], byte[]>> streams = consumerMap.get(topic);
executor = Executors.newFixedThreadPool(CoreConstants.THREAD_SIZE);
for (final KafkaStream stream : streams) {
executor.submit(new KafkaMessageListenerThread(this, stream));
}
} catch (Exception e) {
System.out.println("eror in polling");
}
}
消费者资产
key.deserializer=org.apache.kafka.common.serialization.StringDeserializer
value.deserializer=com.xx.RawFileSerializer
zookeeper.connect=zookeeper.xx\:2181
serializer.class=com.xx.RawFileEncoderDecoder
bootstrap.servers=kafka.xx\:9092
group.id=test
consumer.timeout.ms=-1
fetch.min.bytes=1