onError method not getting invoked on LoggingProducerListener exception #2303
Replies: 4 comments 11 replies
-
What you are talking about is not a thrown exception, it is a log message under ERROR category.
So, probably better to inject your own In two words: the |
Beta Was this translation helpful? Give feedback.
-
The LoggingProducerListener operates asynchronously as part of Spring Kafka’s message production pipeline. When you send a message using a Kafka template, it typically doesn't block the main thread. Instead, the message is sent in the background, and any exceptions are handled by the producer listener configured in Spring Kafka. The onError method in the listener is invoked when an exception occurs during the asynchronous send operation. Since this is outside the scope of your code's synchronous execution, try-catch blocks in your main logic won’t capture these exceptions. |
Beta Was this translation helpful? Give feedback.
-
To handle exceptions from the LoggingProducerListener, you can customize the producer listener or implement a new one. For example: Custom Producer Listener: Implement your own ProducerListener to handle errors in the onError method: |
Beta Was this translation helpful? Give feedback.
-
Review Error Handling in Spring Kafka: Use Spring Kafka’s default exception handling mechanisms, such as retries or a dead-letter topic, to ensure robust processing. |
Beta Was this translation helpful? Give feedback.
-
I have a logic in onError method which needs to be invoked whenever there is a LoggingProducerListener exception. I are not able to catch this exception through try catch block also. I need to know why this exception occurs and how to handle/catch these exceptions. Below is the exception I am encountering.
2022-06-10 15:22:01.126 ERROR 1 --- [ad | producer-1] o.s.k.support.LoggingProducerListener : Exception thrown when sending a message with key='null' and payload='{123, 34, 116, 114, 97, 99, 101, 115, 34, 58, 32, 123, 34, 115, 101, 114, 118, 105, 99, 101, 78, 97,...' to topic
Beta Was this translation helpful? Give feedback.
All reactions