Skip to content

Commit

Permalink
update: Updated Kafka Retry AOP
Browse files Browse the repository at this point in the history
  • Loading branch information
koreanMike513 committed Jan 29, 2025
1 parent bf7bfe6 commit 7b8d787
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.f_lab.joyeuse_planete.core.exceptions.ErrorCode;
import com.f_lab.joyeuse_planete.core.util.log.LogUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.common.KafkaException;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
Expand All @@ -26,7 +27,7 @@ public Object kafkaRetry(ProceedingJoinPoint joinPoint) {
while (attempts < MAX_RETRY) {
try {
return joinPoint.proceed();
} catch (Throwable e) {
} catch (KafkaException e) {
LogUtil.retry(++attempts, joinPoint.getSignature().toString());

try {
Expand All @@ -35,9 +36,13 @@ public Object kafkaRetry(ProceedingJoinPoint joinPoint) {
LogUtil.exception(joinPoint.getSignature().toString(), ex);
throw new JoyeusePlaneteApplicationException(ErrorCode.KAFKA_RETRY_FAIL_EXCEPTION, ex);
}
} catch (Throwable e) {
LogUtil.exception(joinPoint.getSignature().toString(), e);
throw new JoyeusePlaneteApplicationException(ErrorCode.KAFKA_RETRY_FAIL_EXCEPTION, e);
}
}

throw new JoyeusePlaneteApplicationException(ErrorCode.KAFKA_RETRY_FAIL_EXCEPTION);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public abstract class KafkaConsumerConfig {
LogUtil.exception("KafkaConsumerConfig.defaultDeadLetterTopicStrategy", ex);

record.headers().add(KafkaHeaders.EXCEPTION_FQCN, ex.getClass().getName().getBytes());
record.headers().add(KafkaHeaders.EXCEPTION_MESSAGE, ex.getMessage().getBytes());
record.headers().add(KafkaHeaders.EXCEPTION_MESSAGE, ((ex.getMessage() != null) ? ex.getMessage() : "null").getBytes());
record.headers().add(KafkaHeaders.ORIGINAL_TOPIC, record.topic().getBytes());

return new TopicPartition(deadLetterTopic, -1);
Expand Down

0 comments on commit 7b8d787

Please sign in to comment.