-
Notifications
You must be signed in to change notification settings - Fork 37.9k
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
Add support for Coroutines transactions #22915
Comments
On a related note: Reactive Transaction Manager integrations for R2DBC and MongoDB are currently in progress. They bind their transactional state to Reactor's subscriber |
Depends on Kotlin/kotlinx.coroutines#284 where a PR is WIP. |
Moving this one to RC2 since Reactor - Coroutines context is not complete yet, see Kotlin/kotlinx.coroutines#284 (comment) for more details. |
@sdeleuze looks like the work in Kotlin/kotlinx.coroutines#284 was done and released in kotlinx.coroutines 1.3.0-RC2 |
I think for annotations it should work with latest Spring Framework master and kotlinx.coroutines |
Looks like it is working only if a reactive(returning publisher) controller method is annotated with @transactional and the rest of the call chain is suspending functions. |
Looks like the issue comes from Lines 324 to 329 in 0d3fb0e
when the return type of the suspending function is not Deferred or Flow(has no ReactiveAdapter), it gets executed as a regular transaction using ThreadLocal instead of Reactive transaction |
This commits adds Coroutines extensions for TransactionalOperator.transactional that accept suspending lambda or Kotlin Flow parameters. @transactional on suspending functions is not supported yet, spring-projectsgh-23575 has been created for that purpose. This commit also renames invokeHandlerMethod to invokeSuspendingFunction in CoroutinesUtils. Closes spring-projectsgh-22915
This commits adds Coroutines extensions for TransactionalOperator.transactional that accept suspending lambda or Kotlin Flow parameters. @transactional on suspending functions is not supported yet, spring-projectsgh-23575 has been created for that purpose. This commit also renames invokeHandlerMethod to invokeSuspendingFunction in CoroutinesUtils. Closes spring-projectsgh-22915
This commits adds Coroutines extensions for TransactionalOperator.transactional that accept suspending lambda or Kotlin Flow parameters. @transactional on suspending functions is not supported yet, spring-projectsgh-23575 has been created for that purpose. Closes spring-projectsgh-22915
As a follow-up of spring-projectsgh-22915, the purpose of this commit is to improve Coroutines programmatic transaction API to make it more consistent with the Java one and more idiomatic. For suspending functions, this commit changes the TransactionalOperator.transactional extension with a suspending lambda parameter to a TransactionalOperator.executeAndAwait one which is conceptually closer to TransactionalOperator.execute Java API so more consistent. For Flow, the TransactionalOperator.transactional extension is correct but would be more idiomatic as a Flow extension. This commit also adds code samples to the reference documentation. Closes spring-projectsgh-23627
As a follow-up of spring-projectsgh-22915, the purpose of this commit is to improve Coroutines programmatic transaction API to make it more consistent with the Java one and more idiomatic. For suspending functions, this commit changes the TransactionalOperator.transactional extension with a suspending lambda parameter to a TransactionalOperator.executeAndAwait one which is conceptually closer to TransactionalOperator.execute Java API so more consistent. For Flow, the TransactionalOperator.transactional extension is correct but would be more idiomatic as a Flow extension. This commit also adds code samples to the reference documentation. Closes spring-projectsgh-23627
As a follow-up of gh-22915, the purpose of this commit is to improve Coroutines programmatic transaction API to make it more consistent with the Java one and more idiomatic. For suspending functions, this commit changes the TransactionalOperator.transactional extension with a suspending lambda parameter to a TransactionalOperator.executeAndAwait one which is conceptually closer to TransactionalOperator.execute Java API so more consistent. For Flow, the TransactionalOperator.transactional extension is correct but would be more idiomatic as a Flow extension. This commit also adds code samples to the reference documentation. Closes gh-23627
Hi, what is the state of this feature? 🙂 Is it already implemented or do we still have to use |
It is implemented. |
Well then I would be glad if you could help me with my issue here: https://stackoverflow.com/questions/68590209/spring-transactional-on-suspend-function |
Hi @paulschuetz did you figure out how to solve your issue? I'm having a similar problem. Thanks! |
Currently spring transactions bind to ThreadLocal.
Are there any plans to support binding to Kotlin coroutines?
For example @transactional over a suspend function maybe should
bind to the coroutine context regardless of the executing thread.
The text was updated successfully, but these errors were encountered: