Kafka consumer fails on commit offset and rebalancing

859 views Asked by At

i have a Kafka consumer which is subscribed to only one topic. At a certain point in time, after working correctly, i get the following messages in my logs:

Line 25694: 2017-05-15 17:59:53.656 [INFO ] [MeasureConsumerExecutor] AbstractCoordinator - Attempt to heart beat failed since the group is rebalancing, try to re-join group.
Line 25739: 2017-05-15 18:01:39.745 [INFO ] [MeasureConsumerExecutor] AbstractCoordinator - Marking the coordinator 2147483647 dead.
Line 25740: 2017-05-15 18:01:39.745 [WARN ] [MeasureConsumerExecutor] ConsumerCoordinator - Auto offset commit failed: null
Line 25766: 2017-05-15 18:10:52.539 [INFO ] [MeasureConsumerExecutor] AbstractCoordinator - Marking the coordinator 2147483647 dead.
Line 25789: 2017-05-15 18:25:51.036 [INFO ] [MeasureConsumerExecutor] AbstractCoordinator - Marking the coordinator 2147483647 dead.
Line 25790: 2017-05-15 18:25:52.241 [WARN ] [MeasureConsumerExecutor] ConsumerCoordinator - Auto offset commit failed: null
Line 25796: 2017-05-15 18:31:10.354 [INFO ] [MeasureConsumerExecutor] AbstractCoordinator - Marking the coordinator 2147483647 dead.
Line 25797: 2017-05-15 18:31:24.101 [INFO ] [MeasureConsumerExecutor] EventConsumer - run() - WARN - msg: KafkaConsumer will be CLOSED!

My code is really simple:

private final AtomicBoolean closed = new AtomicBoolean(false); ...
...
...
try {   
        while (!closed.get()) {
            ConsumerRecords<String, Message> records = kafkaConsumer.poll(Long.MAX_VALUE);
            for (ConsumerRecord<String, Message> record : records) {
                Message message = record.value();
                messageArrived(message);
            }
        }
        logger.info("run() - NOTIFY - msg: idConsumer = [{}] HAS !closed.get() = [{}]", consumerId, !closed.get());
    } catch (WakeupException wakeupException) {
        logger.error("run() - ERROR - msg: Error on Consumer [{}] caused by = [{}]", getConsumerId(), wakeupException.getMessage(), wakeupException);
        // Ignore exception if closing 
        if (!closed.get()) 
            throw wakeupException;
    } catch (KafkaException kafkaException) {
        logger.error("run() - ERROR - msg: Error on Consumer [" + getConsumerId() + "] caused by = [" + kafkaException.getMessage() + "]", kafkaException);
    } catch (Exception exception) {
        logger.error("run() - ERROR - msg: Error on Consumer [" + getConsumerId() + "] caused by = [" + exception.getMessage() + "]", exception);
    } finally {
        logger.info("run() - WARN - msg: KafkaConsumer will be CLOSED!");
        if (null != kafkaConsumer) {
            kafkaConsumer.close();
        }
    }
}

The strange thing is that i get the last WARN log ("KafkaConsumer will be CLOSED") without entering into exceptions logs (so apparently no exceptions) and without the "closed" variable being changed nowhere.

I have multiple consumers that runs like this one in parallel on different topics but i think this is not relevant. The broker is on a different physical machine in the same subnet.

Could you please give me some hints about what is happening here and how can i handle this issue to prevent consumer disconnection or at least being able to recovery from it?

Thanks so much in advance.

0

There are 0 answers