thoughtvur.blogg.se

Kotlin coroutines gradle
Kotlin coroutines gradle












kotlin coroutines gradle

The resulting high level architecture looks similar:

kotlin coroutines gradle

The counter should be effectively infinite in either direction (+/-).The service must be reactive and nonblocking.The microservice must communicate via REST.Watch a stream of updates to the counter.The requirements are identical to last time. We’re going to rebuild the counter we wrote two years ago using a Spring/Reactor integration with Kotlin Coroutines to make it look cleaner. Unfortunately, we still have a race condition where the stream may not reflect the events in the order they were sent, but they should all be there. Before, we were limited to one node because the stream as all in memory on a single node. Offloading the event publication and subscription to Redis allows us to simplify our application and scale it out if we ever needed to. In the version we wrote two years ago, the Redis publish/subscribe commands were blocking and I opted to make the application handle this in memory. The result will be code that is easier to reason about, more succinct, and less verbose.įinally, thanks to updates in Spring Data Redis, we’re able to use Redis publish/subscribe in a reactive way this time. The new version of our counter still uses Reactor, but instead of using it directly, we will use Kotlin Coroutines and let the integration between Reactor and Coroutines handle the complicated stuff for us. In our previous version of the counter, we used the Reactor libraries directly - dealing with Mono, Flux, and subscriptions to them. Coroutines, on the other hand, let us write non-blocking code using an imperative style. One of the reasons I’ve avoided writing too many reactive servers is the fact that I find them harder to reason about and explain. If you want to jump straight to the code, you can check out the repository for this post on GitHub In this post, I will rewrite my original counter application using more up to date tools - Spring Boot 2.3, Kotlin coroutines, and Redis. Thanks to the introduction of Kotlin coroutines and its integration with Spring Boot, it is even easier than before to write reactive Spring Boot applications with Kotlin. A lot has changed since then, and while the code I wrote then would still be fine today, there is now a better way. Over two years ago, I wrote about how easy it is to write reactive servers using Spring Boot and Kotlin














Kotlin coroutines gradle