Setup rsocket stock client rest api
This commit is contained in:
parent
d9444a5925
commit
aea0ee5b22
@ -3,6 +3,7 @@ package com.cubetiqs.wsclient
|
|||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
||||||
import org.springframework.context.annotation.Bean
|
import org.springframework.context.annotation.Bean
|
||||||
import org.springframework.context.annotation.Configuration
|
import org.springframework.context.annotation.Configuration
|
||||||
|
import org.springframework.context.annotation.Profile
|
||||||
import org.springframework.messaging.rsocket.RSocketRequester
|
import org.springframework.messaging.rsocket.RSocketRequester
|
||||||
import org.springframework.web.reactive.function.client.WebClient
|
import org.springframework.web.reactive.function.client.WebClient
|
||||||
|
|
||||||
@ -15,12 +16,14 @@ class ClientConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
fun webClientStockClient(webClient: WebClient): WebClientStockClient {
|
@Profile("sse")
|
||||||
|
fun webClientStockClient(webClient: WebClient): StockClient {
|
||||||
return WebClientStockClient(webClient)
|
return WebClientStockClient(webClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
fun stockClient(requester: RSocketRequester): RSocketStockClient {
|
@Profile("rsocket")
|
||||||
|
fun stockClient(requester: RSocketRequester): StockClient {
|
||||||
return RSocketStockClient(requester)
|
return RSocketStockClient(requester)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,27 @@
|
|||||||
package com.cubetiqs.wsclient
|
package com.cubetiqs.wsclient
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||||
|
import org.springframework.boot.runApplication
|
||||||
|
import org.springframework.http.MediaType
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable
|
||||||
|
import org.springframework.web.bind.annotation.RestController
|
||||||
|
import reactor.core.publisher.Flux
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
class WsClientApplication
|
class WsClientApplication
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
runApplication<WsClientApplication>(*args)
|
||||||
|
}
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
class RestController @Autowired constructor(
|
||||||
|
private val stockClient: StockClient
|
||||||
|
) {
|
||||||
|
@GetMapping("/{symbol}", produces = [MediaType.TEXT_EVENT_STREAM_VALUE])
|
||||||
|
fun getStockPrices(@PathVariable symbol: String): Flux<StockPrice> {
|
||||||
|
return stockClient.priceFor(symbol)
|
||||||
|
}
|
||||||
|
}
|
@ -1 +1,3 @@
|
|||||||
|
|
||||||
|
server.port=8081
|
||||||
|
spring.profiles.active=rsocket
|
Loading…
Reference in New Issue
Block a user