Merge pull request #9398 from alimate/KTLN-46
KTLN-46: Using Retrieve instead of AwaitExchange
This commit is contained in:
commit
676f32a246
|
@ -2,12 +2,11 @@ package com.baeldung.nonblockingcoroutines.controller
|
||||||
|
|
||||||
import com.baeldung.nonblockingcoroutines.model.Product
|
import com.baeldung.nonblockingcoroutines.model.Product
|
||||||
import com.baeldung.nonblockingcoroutines.repository.ProductRepositoryCoroutines
|
import com.baeldung.nonblockingcoroutines.repository.ProductRepositoryCoroutines
|
||||||
|
import kotlinx.coroutines.CoroutineStart
|
||||||
import kotlinx.coroutines.Deferred
|
import kotlinx.coroutines.Deferred
|
||||||
import kotlinx.coroutines.FlowPreview
|
import kotlinx.coroutines.FlowPreview
|
||||||
import kotlinx.coroutines.GlobalScope
|
|
||||||
import kotlinx.coroutines.CoroutineStart
|
|
||||||
import kotlinx.coroutines.coroutineScope
|
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
|
import kotlinx.coroutines.coroutineScope
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.http.MediaType.APPLICATION_JSON
|
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.bind.annotation.PathVariable
|
||||||
import org.springframework.web.reactive.function.client.WebClient
|
import org.springframework.web.reactive.function.client.WebClient
|
||||||
import org.springframework.web.reactive.function.client.awaitBody
|
import org.springframework.web.reactive.function.client.awaitBody
|
||||||
import org.springframework.web.reactive.function.client.awaitExchange
|
|
||||||
|
|
||||||
class ProductControllerCoroutines {
|
class ProductControllerCoroutines {
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -38,7 +36,7 @@ class ProductControllerCoroutines {
|
||||||
webClient.get()
|
webClient.get()
|
||||||
.uri("/stock-service/product/$id/quantity")
|
.uri("/stock-service/product/$id/quantity")
|
||||||
.accept(APPLICATION_JSON)
|
.accept(APPLICATION_JSON)
|
||||||
.awaitExchange().awaitBody<Int>()
|
.retrieve().awaitBody<Int>()
|
||||||
}
|
}
|
||||||
ProductStockView(product.await()!!, quantity.await())
|
ProductStockView(product.await()!!, quantity.await())
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ import org.springframework.http.MediaType
|
||||||
import org.springframework.stereotype.Component
|
import org.springframework.stereotype.Component
|
||||||
import org.springframework.web.reactive.function.client.WebClient
|
import org.springframework.web.reactive.function.client.WebClient
|
||||||
import org.springframework.web.reactive.function.client.awaitBody
|
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.ServerRequest
|
||||||
import org.springframework.web.reactive.function.server.ServerResponse
|
import org.springframework.web.reactive.function.server.ServerResponse
|
||||||
import org.springframework.web.reactive.function.server.bodyAndAwait
|
import org.springframework.web.reactive.function.server.bodyAndAwait
|
||||||
|
@ -37,7 +36,7 @@ class ProductsHandler(
|
||||||
webClient.get()
|
webClient.get()
|
||||||
.uri("/stock-service/product/$id/quantity")
|
.uri("/stock-service/product/$id/quantity")
|
||||||
.accept(MediaType.APPLICATION_JSON)
|
.accept(MediaType.APPLICATION_JSON)
|
||||||
.awaitExchange().awaitBody<Int>()
|
.retrieve().awaitBody<Int>()
|
||||||
}
|
}
|
||||||
return ServerResponse.ok().json().bodyAndAwait(ProductStockView(product.await()!!, quantity.await()))
|
return ServerResponse.ok().json().bodyAndAwait(ProductStockView(product.await()!!, quantity.await()))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue