From aea0ee5b224fdf173e5b1dc2ed14670b564615c8 Mon Sep 17 00:00:00 2001 From: Sambo Chea Date: Sun, 12 Jul 2020 12:33:48 +0700 Subject: [PATCH] Setup rsocket stock client rest api --- .../com/cubetiqs/wsclient/ClientConfig.kt | 7 ++++-- .../cubetiqs/wsclient/WsClientApplication.kt | 23 ++++++++++++++++++- src/main/resources/application.properties | 2 ++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/cubetiqs/wsclient/ClientConfig.kt b/src/main/kotlin/com/cubetiqs/wsclient/ClientConfig.kt index 215a47b..59cf172 100644 --- a/src/main/kotlin/com/cubetiqs/wsclient/ClientConfig.kt +++ b/src/main/kotlin/com/cubetiqs/wsclient/ClientConfig.kt @@ -3,6 +3,7 @@ package com.cubetiqs.wsclient import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.Profile import org.springframework.messaging.rsocket.RSocketRequester import org.springframework.web.reactive.function.client.WebClient @@ -15,12 +16,14 @@ class ClientConfig { } @Bean - fun webClientStockClient(webClient: WebClient): WebClientStockClient { + @Profile("sse") + fun webClientStockClient(webClient: WebClient): StockClient { return WebClientStockClient(webClient) } @Bean - fun stockClient(requester: RSocketRequester): RSocketStockClient { + @Profile("rsocket") + fun stockClient(requester: RSocketRequester): StockClient { return RSocketStockClient(requester) } diff --git a/src/main/kotlin/com/cubetiqs/wsclient/WsClientApplication.kt b/src/main/kotlin/com/cubetiqs/wsclient/WsClientApplication.kt index 42b7f84..4fb414a 100644 --- a/src/main/kotlin/com/cubetiqs/wsclient/WsClientApplication.kt +++ b/src/main/kotlin/com/cubetiqs/wsclient/WsClientApplication.kt @@ -1,6 +1,27 @@ package com.cubetiqs.wsclient +import org.springframework.beans.factory.annotation.Autowired 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 -class WsClientApplication \ No newline at end of file +class WsClientApplication + +fun main(args: Array) { + runApplication(*args) +} + +@RestController +class RestController @Autowired constructor( + private val stockClient: StockClient +) { + @GetMapping("/{symbol}", produces = [MediaType.TEXT_EVENT_STREAM_VALUE]) + fun getStockPrices(@PathVariable symbol: String): Flux { + return stockClient.priceFor(symbol) + } +} \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8b13789..80df0ad 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1,3 @@ +server.port=8081 +spring.profiles.active=rsocket \ No newline at end of file