-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Log conversion failures in batch listeners #3555
Comments
Logging the error in addition to the header is reasonable. However, skipping the record based on a configuration might be more invasive, and we must ensure no side effects. Feel free to submit a PR for this if you are up to it. |
I don't think this is something what has to be done in the framework unconditionally. I would close this as |
The issue with I could implement it on my side by overriding the @Override
protected Object convert(
ConsumerRecord<?, ?> consumerRecord,
Type type,
List<ConversionException> conversionFailures) {
var payload = super.convert(consumerRecord, type, conversionFailures);
if (payload == null) {
var conversionFailure = conversionFailures.getLast();
if(conversionFailure != null) {
log.error("Could not convert message for topic={}, partition={}, offset={}",
consumerRecord.topic(),
consumerRecord.partition(),
consumerRecord.offset(),
conversionFailure);
}
return null;
}
return payload;
} Another option I see and probably how this mechanism with exceptions as headers is intended to be used: Inject all needed headers into every listener (in this case topic, partition, offset and conversion failures) and call a helper method from the listener to log the conversion failures. If you feel this should be handled by the target project you can close this issue. Still, it might also be valuable to add a note to https://docs.spring.io/spring-kafka/reference/kafka/serdes.html#payload-conversion-with-batch that by default messages that can't be converted will be passed with a |
…LURES` Fixes: spring-projects#3555 Issue link: spring-projects#3555 The batch might be processed in the `@KafkaListener` silently without looking into conversion failures header. So, that might cause in impression that nothing is wrong with the batch. * Mention `KafkaHeaders.CONVERSION_FAILURES` in the docs * Add `warn` for the failed conversion in the `BatchMessagingMessageConverter` * Some other code optimization clean up in the `BatchMessagingMessageConverter`
Current Behavior
When using a batch listener the
BatchMessagingMessageConverter
will put anyConversionException
s into theCONVERSION_FAILURES
header and provide anull
payload for this message in the batch passed to the listener.The exception is not visible in the log at all. The error handling is left up completely to the listener, that needs to inject the header and act on it.
Expected Behavior
In addition to putting the exception in the header it should also be logged as error or warning.
Optional: Provide a configuration property to skip such messages completely after logging the error instead of providing them with a
null
payload to the listener.The text was updated successfully, but these errors were encountered: