Skip to content

Non-Blocking Retries cannot combine with container transactions. #3072

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

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ Instead, use a `KafkaTransactionManager` in the container to start the Kafka tra

See xref:tips.adoc#ex-jdbc-sync[Examples of Kafka Transactions with Other Transaction Managers] for an example application that chains JDBC and Kafka transactions.

IMPORTANT: xref:retrytopic.adoc[Non-Blocking Retries] cannot combine with xref:kafka/transactions.adoc#container-transaction-manager[Container Transactions].
When listener code threw exception, container transactions commit success and record sending to the retryable topic.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that what expected from asynchronous, non-blocking retries?
To be able to send to the retry topic we indeed has to commit the current transaction.
I'm not fully sure how this non-blocking retires work internally, but apparently we don't start a new transaction, when we consume from the next retry topic.

It might work some way with a @Transactional on the @KafkaListener, but pay attention that @EnableTransactionManagement has to be activated.

Either way: I would not say in the docs break.
It sounds like a bug which is not supposed to be there.

It is just a feature which cannot be combined with transactions due to async nature.

Do you see things differently?

Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agree with you, i'll re-test the @Transactional case.

Copy link
Contributor Author

@Wzy19930507 Wzy19930507 Feb 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test result is non-blocking retries cannot be combined with transactions.


@Transactional case as follows:
When PROPAGATION_REQUIRED will infinite retry because of container transactions rollback. (un-expected).
When PROPAGATION_REQUIRED_NEW

  1. If listener code fail and container code success, listener code rollback, container code commit success. (expected)
  2. If listener code fail and container code fail, listener code rollback, container code rollback. (expected)
  3. If listener code success and container code fail, listener code commit success, container code rollback then infinite retry. (un-expected)
    Current KafkaTransactionManager only support PROPAGATION_REQUIRES_NEW and PROPAGATION_REQUIRED, the above case tests only these two cases.

PROPAGATION_REQUIRED_NEW un-expected Report see https://github.com/Wzy19930507/spring-kafka/tree/report_pr_3072

Please see if there are any omissions, thanks.


I'll modify docs to Non-blocking retries cannot be combined with container transactions first and see if there's a way to implement it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Wzy19930507 We might want to use present tense here: When the listener code throws an exception, container transaction commit succeeds, and the record is sent to the retryable topic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the correction, fix it.


[[kafkatemplate-local-transactions]]
== `KafkaTemplate` Local Transactions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ Since 2.7 Spring for Apache Kafka offers support for that via the `@RetryableTop

IMPORTANT: Non-blocking retries are not supported with xref:kafka/receiving-messages/listener-annotation.adoc#batch-listeners[Batch Listeners].

IMPORTANT: Non-Blocking Retries cannot combine with xref:kafka/transactions.adoc#container-transaction-manager[Container Transactions].