🤍 전 강의 25% 할인 중 🤍

2024년 상반기를 돌아보고 하반기에도 함께 성장해요!
인프런이 준비한 25% 할인 받으러 가기 >>

  • 카테고리

    질문 & 답변
  • 세부 분야

    데이터 엔지니어링

  • 해결 여부

    해결됨

백그라운드 스레드 Sender에 대한 예외처리도 가능한가요?

23.10.06 14:35 작성 23.10.06 14:36 수정 조회수 212

0

KafkaProducer의 send 메소드를 try-catch 하면 아래와 같은 예외는 잡을 수 있는데요

 

Throws:

AuthenticationException – if authentication fails. See the exception for more details

AuthorizationException – fatal error indicating that the producer is not allowed to write

IllegalStateException – if a transactional.id has been configured and no transaction has been started, or when send is invoked after producer has been closed.

InterruptException – If the thread is interrupted while blocked

SerializationException – If the key or value are not valid objects given the configured serializers

TimeoutException – If the record could not be appended to the send buffer due to memory unavailable or missing metadata within max.block.ms.

KafkaException – If a Kafka related error occurs that does not belong to the public API exceptions.


Batch 로 레코드를 묶어서 실제로 브로커에게 전송하는 Sender Thread 에서 네트워크 이슈 등으로 실패하면 어떻게 처리해야할지가 궁금합니다.

(retries가 아닌 예외로 잡는 방법이 없을까요? ㅠㅠ)

답변 1

답변을 작성해보세요.

0

안녕하십니까,

네트웍 장애가 광범위해서 Exception을 특정할 수는 없지만, 보통은 네트웍 문제 시 TimeoutException이 발생합니다.

TimeoutException 설명은 아래와 같이 send buffer에 메모리가 더 이상 여유가 없어서 발생한다고 되어 있습니다.

imeoutException – If the record could not be appended to the send buffer due to memory unavailable or missing metadata within max.block.ms.

근데 주로 send buffer에 메모리가 가득 차는 이유는 Sender Thread가 네트웍이나 Kafka Broker가 Down되는 경우등으로 인해서 Kafka Broker로 메시지를 보내지 못하기 때문에 send buffer가 비워지지 않고 가득 차는 이유가 가장 큽니다.

때문에 네트웍에 문제가 생기면 주로 TimeoutException이 발생합니다.

 

감사합니다.

Sender 구현체 코드를 분석하니 Producer Callback 을 통해서 예외를 핸들링 할 수 있네요

답변 감사합니다

채널톡 아이콘