Search code examples
springspring-kafka

Opportunity to catch, log, and rethrow exception when an exception occurs in kafka listener container?


I want to catch an exception that occurs within kafka listener container, log some attributes from the exception, then rethrow the exception. What is the best way to do this without modifying the existing error handling flow?


Solution

  • Add a MethodInterceptor to the container's adviceChain.

    https://docs.spring.io/spring-kafka/docs/current/reference/html/#adviceChain