I have a Java consumer that runs continuously with a lot of data and messages.. sometimes, the program gets stuck on consumer.poll the data.. it seems like deadlock or infinite loop but I’m not sure about it. There is no exception thrown and the program seems to work properly, although it doesn’t polls the actual data. (The problem happens only in the java program.. I run console consumer and it works great)
The only way to fix it, is by restarting the program...
public class Main {
Properties consumerComfig = new Properties ();
consumerConfig.put(ConsumerConfig. KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArrayDeserializer");
consumerConfig.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG,"Org.apache.kafka.comnect.json.JsonDeserializer");
consumerConfig.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "some server")
consumerConfig.put(ConsumerConfig.GROUP_ID_CONFIG, UUID.randomUUID());
consumerConfig.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, "false"):
consumerConfig.put(ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG, 30000);
consumerConfig.put(ConsumerConfig.HEARTBEAT_INTERVAL_MS_CONFIG,10000)
consumerConfig.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "latest"):
consumer = new KafkaConsumer<String, JsonNode> (consumerConfig);
public void consumeAndSendToCorrelator () {
logger.info ("Starting kafka consumer, listening to topics stringBuilder.toString ()");
try {
consumer.subscribe("INPUT TOPICS");
while (true) {
ConsumerRecords<String, JsonNode> records = consumer.poll(8000);
logger.debug("Trying to pull records from consumer");
JsonNode value = null;
for (Consumer Record<String, JsonNode > irecord :records){
try {
value = record.value();
if (value == null)
continue;
//Somme thread that process the message
correlatorActor.tell(value, ActorRef.noSender);
} catch (JsonProcessingException e) {
logger.error("Could not parse incoming json" + value.toString());
} catch (IOException e) {
logger.error("IOException occurred", e);
} catch (Exception e) {
logger.error("Error occurred", e);
}
consumer.commitSync();
}
}
}catch(WakeupException e) {
logger.info("closed consumer");
}finally {
consumer.close()
}
}
}
I use Kafka 0.10 Do you know what happens to it ? What can I do to fix it?