Kafka Consumer挂在Java中的.hasNext [英] Kafka Consumer hanging at .hasNext in java
本文介绍了Kafka Consumer挂在Java中的.hasNext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Java中有一个简单的Kafka Consumer,带有以下代码
I have a simple Kafka Consumer in java with the following code
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()会保持待处理状态,再也不会返回.
When a message is posted, the data is read successfully, however when it goes back to checking it.hasNext(), it stays pending and never comes back.
这会阻止什么?
m_stream是如下获得的KafkaStream:
m_stream is a KafkaStream obtained as follows:
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"
"consumer.timeout.ms"
现在,当达到超时时,将引发ConsumerTimeoutException
Now when the timeout is reached a ConsumerTimeoutException is thrown
这篇关于Kafka Consumer挂在Java中的.hasNext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文