-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support KafkaListener to fail on records and stop consuming #892
Comments
I am having the same issue, if there is an exception when consuming a record it's just logged as an error and the consumer moves to the next record. |
as a workaround you could use sthg like this should work (kotlin project)
|
@cristianbriscaru not sure I understand. The @frisi if you don't define a retry count it will retry indefinitely, what behaviour are you after? |
Hi @graemerocher , I am using ErrorStrategy but when the kafka listener is reactive the message is not retired on error @Slf4j
@RequiredArgsConstructor
@KafkaListener(
value = "${kafka.consumers.ledger-company.group.id}",
offsetReset = OffsetReset.EARLIEST,
offsetStrategy = OffsetStrategy.SYNC,
errorStrategy = @ErrorStrategy(
value = ErrorStrategyValue.RETRY_ON_ERROR,
retryDelay = "100ms",
retryCount = 999999999
)
)
public class CompanyListener {
private final LedgerService ledgerService;
@Topic("${kafka-topics.company}")
public Mono<Void> receive(ConsumerRecord<String, DomainEventValue<CompanyProto>> message) {
var eventType = message.value().getEventType();
if (eventType.equals(CompanyEventTypes.CREATED)) {
return ledgerService.create(LedgerExternalId.from(message.value().getEntity().get().getId()))
.then();
}
return Mono.empty();
}
} In this case the listener will throw an "Error processing record ..." once and move on without retrying , if I What is the proper way to have a reactive kafka listener without using |
@cristianbriscaru You don't need to have this support on micronaut-kafka level at all. You can define retry strategy on your Mono created by ledger service. Example return ledgerService.create(LedgerExternalId.from(message.value().getEntity().get().getId()))
.retryWhen(Retry.backoff(Integer.MAX_VALUE, Duration.ofMillis(100)));
.then(); so it will keep retrying your message repeatedly with 100ms backoff. Tip: just make sure you get warning that a consumer is stuck ⚠ |
Feature description
Current behaviour
If the Listener fails while processing a record at offset N, it resumes at the offset N+1
I guess this is due to the decision made in #372
to chose availability over consistency.
Expected behaviour
There should be a way to configure KafkaListener to stop consuming records for a topic-partition if a record failed.
If configured to
RETRY_ON_ERROR
it should re-tryretryCount
times. If it still fails, log an error and stop processing.IIUC as of micronaut-kafka 5.1.2 there is no way to tell the listener to stop consuming orther records if if failed
(or re-try indefinititely if errorStrategy RETRY_ON_ERROR is configured)
Or is there?
The text was updated successfully, but these errors were encountered: