Merge pull request #9398 from alimate/KTLN-46

KTLN-46: Using Retrieve instead of AwaitExchange
This commit is contained in:
Eric Martin 2020-06-05 17:45:12 -05:00 committed by GitHub
commit 676f32a246
2 changed files with 4 additions and 7 deletions

View File

@ -2,12 +2,11 @@ package com.baeldung.nonblockingcoroutines.controller
import com.baeldung.nonblockingcoroutines.model.Product
import com.baeldung.nonblockingcoroutines.repository.ProductRepositoryCoroutines
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.Flow
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.MediaType.APPLICATION_JSON
@ -15,7 +14,6 @@ import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.reactive.function.client.WebClient
import org.springframework.web.reactive.function.client.awaitBody
import org.springframework.web.reactive.function.client.awaitExchange
class ProductControllerCoroutines {
@Autowired
@ -38,7 +36,7 @@ class ProductControllerCoroutines {
webClient.get()
.uri("/stock-service/product/$id/quantity")
.accept(APPLICATION_JSON)
.awaitExchange().awaitBody<Int>()
.retrieve().awaitBody<Int>()
}
ProductStockView(product.await()!!, quantity.await())
}

View File

@ -12,7 +12,6 @@ import org.springframework.http.MediaType
import org.springframework.stereotype.Component
import org.springframework.web.reactive.function.client.WebClient
import org.springframework.web.reactive.function.client.awaitBody
import org.springframework.web.reactive.function.client.awaitExchange
import org.springframework.web.reactive.function.server.ServerRequest
import org.springframework.web.reactive.function.server.ServerResponse
import org.springframework.web.reactive.function.server.bodyAndAwait
@ -37,7 +36,7 @@ class ProductsHandler(
webClient.get()
.uri("/stock-service/product/$id/quantity")
.accept(MediaType.APPLICATION_JSON)
.awaitExchange().awaitBody<Int>()
.retrieve().awaitBody<Int>()
}
return ServerResponse.ok().json().bodyAndAwait(ProductStockView(product.await()!!, quantity.await()))
}