我在Java中有一个简单的Kafka Consumer,带有以下代码
public void run() {
ConsumerIterator<byte[], byte[]> it = m_stream.iterator();
while (it.hasNext()&& !done){
try {
System.out.println("Parsing data");
byte[] data = it.next().message();
System.out.println("Found data: "+data);
values.add(data); // array list
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
}
done = true;
}
发布消息后,将成功读取数据,但是当它返回检查它时。hasNext(),它将保持待处理状态,再也不会返回。
什么会拖延这个?
m_stream是通过以下方式获得的KafkaStream:
Map<String, Integer> topicCountMap = new HashMap<String, Integer>();
topicCountMap.put(topic, new Integer(a_numThreads));
Map<String, List<KafkaStream<byte[], byte[]>>> consumerMap = consumer.createMessageStreams(topicCountMap);
List<KafkaStream<byte[], byte[]>> streams = consumerMap.get(topic);
executor = Executors.newFixedThreadPool(a_numThreads);
for (final KafkaStream stream : streams) {
// m_stream is one of these streams
}
解决方案是添加属性
“ consumer.timeout.ms”
现在,当达到超时时,将引发ConsumerTimeoutException
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句