본문 바로가기
AMQP/Kafka

Kafka DLT 활용해서 재시도 처리 /w Spring

by Bill Lab 2025. 5. 5.
728x90

Kafka 내에서는 message 처리에 실패한 message 를 저장하는 별도의 topic 이 있다.

= DLT

 

처리 실패한 message 를 Kafka with spring 기능을 활용해서 자동 retry 를 설정할 수 있다.

 

이는 Transactional outout pattern 의 동작원리와는 다른 구성이다. DLT 의 경우 Kafka 자체의 message 전달 실패에만 사용이가능하다.

하나의 예로, consumer 에서 토픽을 받자말자 error 를 return 하게 되면 kafka 는 이를 오류로 인식하고 message 전달의 실패로 간주하게 된다.

 

하지만 consumer 전달은 잘 받고 consumer 에 연결된 서비스 로직을 수행중에 오류가 나게되면, DLT 로 message 가 저장되지 않는다.

 

@RetryableTopic(
	attempts = 3,
    backoff = @Backoff(delay = 2000, multiplier = 2.0)
    delay = 1000,           
    multiplier = 2.0,        
    dltTopicSuffix = ".dlt"
    include = { RecoverableException.class },
    exclude = { NonRecoverableException.class }
)
@KafkaListener(groupId = "groupTest", topics = "topicTest")
public void testConsumer(String message) {
    try{
    	call.bizLogic;
    }catch(RecoverableException e){
    	throw e;
    }catch(NonRecoverableException e){
    	throw e;
	}
}

 

 

 

 

 

728x90