Search code examples
apache-kafkakafka-consumer-apispring-kafka

Kafka Consumer how to poll automatically if message is not committed


I have a Kafka consumer where the messages are passed to another application using a HTTP POST call. I am also manually committing the offset using

acknowledgment.acknowledge();

There are some HTTP return error codes where we ignore the error and commit the offsets and there are some error codes where we don't commit the offsets. The issue is that the kafka consumer is polling for the non committed messages only when I restart the consumer. Is there anyway where I can poll for the messages if there are uncommitted messages in the partitions?


Solution

  • See this answer for an explanation.

    To redeliver a record, you must throw an exception, in conjunction with a SeekToCurrentErrorHandler, which repositions the unprocessed partitions so they are fetched again on the next poll.

    Or you can nack() the acknowledgment to achieve a similar result.