-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Offset is committed after the rollback of the DB transaction #2775
Comments
It makes no sense to not commit the offset - a successful commit of the next record in the partition will effectively commit it anyway. That is the whole intent of providing a recoverer to the Setting a Jpa transaction manager on the container is not really recommended; this is for a You can simply use In that case, add the recoverer to the |
Hi @garyrussell, thanks for you prompt reply. Some questions to build a better understanding here. (1)
If that is the case, why does (2) |
spring-kafka/spring-kafka/src/main/java/org/springframework/kafka/listener/CommonErrorHandler.java Lines 199 to 213 in 7b9a0cb
If you want more control over when offsets are committed, use one of the manual |
For point 2, we observe different behaviour (same configuration) depending on where the exception happens:
Other aspects behave the same (retries, error handler, etc), the difference is only in committing offset. It is this difference that we find confusing and hard to explain without knowing the implementation details of Spring Kafka. |
If that's the case then it is, indeed, a bug. But, if you switch to using |
…nsactionManager Use `KafkaAwareTransactionManager` to properly manage Kafka transactions. * Deprecated properties transactionManager and add kafkaAwareTransactionManager at ContainerProperties. * Modify transaction unit test to `setKafkaAwareTransactionManager. Resolves spring-projects#2775
In what version(s) of Spring for Apache Kafka are you seeing this issue?
Tested on v3.0.8, previous versions are affected as well
Describe the bug
We are using
JpaTransactionManager
inConcurrentKafkaListenerContainerFactory
to start new DB transactions in consumers.We've noticed that
spring-kafka
commits offset despite the error during the commit of the DB transaction.This behavior is unexpected because an error has occurred and retries have been conducted as well.
Therefore, we are expecting that the offset will not be committed and it should work in the same way as when the consumer throws an exception.
Retries are working fine
To Reproduce
Create a container factory and use
JpaTransactionManager
thereand consumer
Expected behavior
Offset is not committed into the consumer group because of an error during the commit of the DB transaction
The text was updated successfully, but these errors were encountered: