is there any documentation on how to fully use cor...
# spring
t
is there any documentation on how to fully use coroutines+Spring (reactive)? What i do know is that in principal everything should work. but when it comes to db transactions or spring security i feal unsure about how to handle the reactor Context, how it interacts with the corouting context and what i do have to do in order everything works or what does already work ootb.
👍 1
n
j
@thana are you building a web server? Using WebFlux?
Database calls are often blocking (if not using r2dbc). Wrap any blocking code in
withContext(<http://Dispatchers.IO|Dispatchers.IO>)
to offload them to a thread pool specifically for this purpose. The only gotcha I have found in spring-security is that method authorization (i.e.
@PreAuthorize
, etc) are not compatible with suspending functions. But it's easy enough to wrap with a mono i.e.
fun index() = mono { // now I am in a suspended context }
.
t
@Joel so you mean in spring security suspending are not supported yet but methods returning a reactive type are, so annotations work with them?
j
Yes. Have not had any issues using asynchronous code w/ spring-security. Just that nit when it comes to method security.
The recently released kotlin security DSL is really slick btw
s
Not yet official guide but that's planned.
For now you can check https://github.com/sdeleuze/spring-boot-coroutines-demo for the web part.
🙏 1
For the persistence I would advise to use Spring Boot 2.4.x integratio of R2DBC or Spring Data Reactive NoSql bits with Coroutines extensions.
If you need to use regular Spring Data API (not Coroutines based natively) or other solution like jOOQ that's probably that you should use Spring MVC not WebFlux.
If you have more specific question please let me know.
t
I think all the fear that came up in me stems from the fact, that for almost 20 years i was used to implicitly rely on the one-thread-per-requests-semantics which now falls apart and i realize how much i was relying on alle the magic happening in the background. realizing that i finally the feeling emerges to understand what was taken for granted all the time before
👍 1
s
Yeah i can understand that feeling. We have introduced Reactor context with Coroutines interop in order to continue to use security and transactions in that Reactive/Coroutines context.
t
@sdeleuze yeah read that and i;m eager to understand 🙂
166 Views