我有一个非阻塞重试尝试的Kafka Consumer
@RetryableTopic(attempts = "2", backoff = @Backoff(delay = 3000, multiplier = 1.5, maxDelay = 15000))
@KafkaListener(topics = "my-topic")
public void consume(
@Header(KafkaHeaders.RECEIVED_TOPIC) String receivedTopic,
MyEvent event) {
...
//consumer logic here
...
}
通过这种方式,当发生错误时,消费者在将事件发送到DLQ主题之前重试处理2次。
有一种方法,当重试尝试超时时,只需记录一个自定义错误消息(或执行一些自定义逻辑),避免尝试将事件发送到DLQ?
1条答案
按热度按时间fhity93d1#
重试处理% 2
attempts
包括初始传递,因此2意味着仅重试1次。要防止创建DLT,请将
dltStrategy = DltStrategy.NO_DLT
添加到@RetryableTopic
注解。https://docs.spring.io/spring-kafka/docs/current/reference/html/#configuring-no-dlt