Hi All! For exercise only, I'm trying to replace P...
# coroutines
d
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
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
Thanks
For your information I am currently working on adding
Flow
based APIs to Spring Data Redis.
l
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
What version of Spring Boot do you use ? Annotation or functional transactions ?
l
Spring Boot 2.2.0.M5 with annotation transactions. so maybe there is a way to do functional transactions?
s
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
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
Feedback appreciated
๐Ÿ˜„ 1
l
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
@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
Upcoming Spring Boot 2.2 M6
๐Ÿ‘ 1
l
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.