Skip to content
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

How to configure errorHandler when using @RetryableTopic #1863

Closed
TheLeftHandOfGod opened this issue Jul 11, 2021 · 1 comment · Fixed by #1865
Closed

How to configure errorHandler when using @RetryableTopic #1863

TheLeftHandOfGod opened this issue Jul 11, 2021 · 1 comment · Fixed by #1865
Milestone

Comments

@TheLeftHandOfGod
Copy link

TheLeftHandOfGod commented Jul 11, 2021

When I use @RetryableTopic, the errorHandler configuration of @KafkaListener does not take effect and is replaced with SeekToCurrentErrorHandler, I want to print the error stack trace. How should I configure?

@RetryableTopic(
        attempts = "2",
        backoff = @Backoff(delay = 1000L, multiplier = 2.0),
        topicSuffixingStrategy = TopicSuffixingStrategy.SUFFIX_WITH_INDEX_VALUE,
        fixedDelayTopicStrategy = FixedDelayStrategy.SINGLE_TOPIC,
        listenerContainerFactory = "retryKafkaListenerContainerFactory"
)
@KafkaListener(
        topics = TOPIC_ENTERPRISE,
        clientIdPrefix = "enterprise",
        containerFactory = "kafkaListenerContainerFactory",
        errorHandler = "customKafkaListenerErrorHandler"
)
public void enterpriseConsumer(ConsumerRecord<Long, String> record) {
    LOGGER.info("{} - topoc:{}, part: {}, offset: {}, key: {}, value: {}", Thread.currentThread().getName(), record.topic(), record.partition(), record.offset(), record.key(), record.value());
    int i = 1 / 0;
}
@garyrussell
Copy link
Contributor

It's a bug; the error handler is not set up when it's retryable.

It's not actually replaced; the STCEH is a container error handler used to handle the retries. The errorHandler is a KafkaListenerErrorHandler and it is (incorrectly) ignored.

The KLEH must re-throw the exception to make the retries work.

Thanks for reporting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants