K - the type of key for records consumed from KafkaV - the type of value for records consumed from Kafkapublic final class RetriableConsumerRecordHandler<K,V> extends Object implements ConsumerRecordHandler<K,V>
ConsumerRecordHandler to let the wrapped ConsumerRecordHandler try to handle a
record in a limited times in case the handling process failed.| Constructor and Description |
|---|
RetriableConsumerRecordHandler(ConsumerRecordHandler<K,V> wrappedHandler,
int maxRetryTimes)
Constructor for
RetriableConsumerRecordHandler with max retry times limit. |
RetriableConsumerRecordHandler(ConsumerRecordHandler<K,V> wrappedHandler,
int maxRetryTimes,
Duration retryInterval)
Constructor for
RetriableConsumerRecordHandler with max retry times limit and retry interval. |
| Modifier and Type | Method and Description |
|---|---|
void |
handleRecord(org.apache.kafka.clients.consumer.ConsumerRecord<K,V> record)
Handle a
ConsumerRecord consumed from Kafka broker. |
public RetriableConsumerRecordHandler(ConsumerRecordHandler<K,V> wrappedHandler, int maxRetryTimes)
RetriableConsumerRecordHandler with max retry times limit. The returned
RetriableConsumerRecordHandler is a ConsumerRecordHandler which will retry to handle a
ConsumerRecord automatically if it was failed, until the ConsumerRecord was handled successfully
or retried times exceeded maxRetryTimes after which a HandleMessageFailedException will be thrown.wrappedHandler - the wrapped ConsumerRecordHandler.maxRetryTimes - maximum retry times.NullPointerException - when wrappedHandler is nullIllegalArgumentException - if maxRetryTimes is a negative valuepublic RetriableConsumerRecordHandler(ConsumerRecordHandler<K,V> wrappedHandler, int maxRetryTimes, Duration retryInterval)
RetriableConsumerRecordHandler with max retry times limit and retry interval. The returned
RetriableConsumerRecordHandler is a ConsumerRecordHandler which will retry to handle a
ConsumerRecord automatically if it was failed, until the ConsumerRecord was handled successfully
or retried times exceeded maxRetryTimes after which a HandleMessageFailedException will be thrown.wrappedHandler - the wrapped ConsumerRecordHandler.maxRetryTimes - maximum retry times.retryInterval - the interval between every retryNullPointerException - when wrappedHandler or retryInterval is nullIllegalArgumentException - if maxRetryTimes is a negative value or retryInterval is a negative durationpublic void handleRecord(org.apache.kafka.clients.consumer.ConsumerRecord<K,V> record)
ConsumerRecordHandlerConsumerRecord consumed from Kafka broker.
For the sake of fail fast, if any exception throws from this method, the thread for fetching records from Kafka broker will exit with an error message. This will trigger rebalances of partitions among all the consumer groups this consumer joined and let other consumer try to handle the failed and the following records.
You can consider to use RetriableConsumerRecordHandler to retry handling process automatically.
Or use CatchAllExceptionConsumerRecordHandler as a safety net to handle all the failed records in
the same way.
handleRecord in interface ConsumerRecordHandler<K,V>record - the consumed ConsumerRecordCopyright © 2020 LeanCloud. All rights reserved.