:question: How do we make non-blocking http post r...
# spring
a
How do we make non-blocking http post request in springboot? I have service A that is making about 100 or so request to service B. I want service A to make non-blocking http post request, that is make the http post request but don't wait for a response to make another one.
😶 1
e
Not Kotlin, but look into Webflux.
s
You might want to take a look into #coroutines and
launch
as well as Spring WebFlux
a
Thanks
Looking into webflux
s
You should also take a look into kotlinx-coroutines-reactive: https://github.com/Kotlin/kotlinx.coroutines/tree/master/reactive/kotlinx-coroutines-reactive With its extensions, you can easily use Webflux in the kotlin coroutines world: example usage:
Copy code
fun sampleApiCallThatReturnsMono(): Mono<ApiResponse> {
        ...
    }

    suspend fun webClientWithCoroutineExtension(): ApiResponse =
        client.[...].retrieve().awaitBody()

    suspend fun parallelCalls() = coroutineScope {
        val call1 = async { sampleApiCallThatReturnsMono().awaitSingle() }
        val call2 = async { webClientWithCoroutineExtension() }
        println("Call 1 result: ${call1.await()}, Call 2 result: ${call2.await()}")
    }

    suspend fun multipleFireAndForgetCalls() = coroutineScope { 
        repeat(10) {
            launch { webClientWithCoroutineExtension() }
        }
    }