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.wrappedHandler - the wrapped ConsumerRecordHandler.maxRetryTimes - maximum retry times.HandleMessageFailedException - throw when try to handle a ConsumerRecord maxRetryTimes,
the wrapped ConsumerRecordHandler still failed to handle this recordpublic RetriableConsumerRecordHandler(ConsumerRecordHandler<K,V> wrappedHandler, int maxRetryTimes, Duration retryInterval)
RetriableConsumerRecordHandler with max retry times limit and retry interval.wrappedHandler - the wrapped ConsumerRecordHandler.maxRetryTimes - maximum retry times.retryInterval - the interval between every retryHandleMessageFailedException - throw when try to handle a ConsumerRecord maxRetryTimes,
the wrapped ConsumerRecordHandler still failed to handle this recordpublic 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.