https://kotlinlang.org logo
#coroutines
Title
# coroutines
d

davide

09/06/2019, 7:20 AM
Hi All! For exercise only, I'm trying to replace Project Reactor with Coroutine. There is some article/blog post that can help me in this task? Any suggestion will be appreciated 🙂
d

davide

09/06/2019, 4:42 PM
Thanks! Already read 😉 I was just about to tell that I'm using Spring Data Redis, so I'm using .asFlow(), e.g: itemOps.opsForList().range(...).asFlow()
ps: I read many articles written by you. Thanks for everything you are doing with Kotlin and Spring
👍 1
s

sdeleuze

09/06/2019, 4:54 PM
Thanks
For your information I am currently working on adding
Flow
based APIs to Spring Data Redis.
l

leodeng

09/06/2019, 5:51 PM
From my little experiment with reactor and coroutine, it seems to me that transaction management is not supported by coroutine yet, not sure if that’s correct @sdeleuze
s

sdeleuze

09/06/2019, 6:46 PM
What version of Spring Boot do you use ? Annotation or functional transactions ?
l

leodeng

09/06/2019, 7:32 PM
Spring Boot 2.2.0.M5 with annotation transactions. so maybe there is a way to do functional transactions?
s

sdeleuze

09/06/2019, 7:37 PM
2.2.0.M5 does not support Coroutines transactions. Snapshots or upcoming 2.2.0.M6 support functional transactions not those based on annotations. See https://docs.spring.io/spring-framework/docs/5.2.0.RC2/spring-framework-reference/languages.html#transactions.
l

leodeng

09/06/2019, 7:41 PM
Thanks. I'd prefer to using coroutines, and transaction management is the only thing preventing me from doing that. Will try 2.2.0.M6 with functional transations.
👍 1
s

sdeleuze

09/06/2019, 7:41 PM
Feedback appreciated
😄 1
l

leodeng

09/06/2019, 9:19 PM
Just tried, and it's really nice 👍 I think I can migrate most of my old transactional code to use coroutines. I already experimented with reactor Mono/Flux with transactions and they also work perfectly fine, but coroutines just seem more natural to me (it could be just me 🙂. I will spend a little more time on the TransactionalOperator.create(ReactiveTransactionManager transactionManager, TransactionDefinition transactionDefinition) method too. I used to just use annotation with readOnly a lot, and now I may need to create the TransactionDefinition by myself.
Copy code
@Service
class CoroutineUserService(
    private val transactionManager: ReactiveTransactionManager,
    private val userDao: CoroutineUserDao
) {
    suspend fun updateUsers() {
        TransactionalOperator.create(transactionManager).transactional {
            updateUser1()
            updateUser2WithRandomFailure()
        }
    }
    // ...
}
d

davide

09/09/2019, 10:17 AM
@sdeleuze do you have a branch that I can start to use? The project is a demo that I use to study, so it is the right place to try unstable branch 🙂
s

sdeleuze

09/09/2019, 12:13 PM
Upcoming Spring Boot 2.2 M6
👍 1
l

leodeng

09/09/2019, 4:53 PM
I also just started to use the SNAPSHOT versions of spring boot, spring data r2dbc and r2dbc postgresql (0.8.0.BUILD-SNAPSHOT). They used to change a lot, but now they are much more stable.
5 Views