Kafka: A consumer poll loop must not block

Slow work inside the loop trips max.poll.interval.ms and gets the consumer evicted.

Code
// Wrong: 30 seconds of work per record
for (var r : records) { slowHttpCall(r); }

// Right: hand off, or reduce the batch
props.put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, 10);
// or pause()/resume() around long work
Output
Consumer group is rebalancing, the last poll was 312s ago
(max.poll.interval.ms is 300000)
Advertisement
More in KAFKA

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-08-11

© Java Coding Hub · About · Contact · Privacy · Terms