Init wsclient and code tests with rsocket client

This commit is contained in:
2020-07-11 21:01:38 +07:00
commit a26812a6c2
13 changed files with 447 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
package com.cubetiqs.wsclient
import org.springframework.messaging.rsocket.RSocketRequester
import org.springframework.stereotype.Service
import reactor.core.publisher.Flux
@Service
interface StockClient {
fun priceFor(symbol: String): Flux<StockPrice>
}
@Service
class RSocketStockClient (
private val requesterBuilder: RSocketRequester.Builder
) : StockClient {
private fun createRSocketRequester(): RSocketRequester {
return requesterBuilder.connectTcp("localhost", 7000).block() ?: throw Exception("requester not loaded")
}
override fun priceFor(symbol: String): Flux<StockPrice> {
return createRSocketRequester().route("stockPrices")
.data(symbol)
.retrieveFlux(StockPrice::class.java)
}
}

View File

@@ -0,0 +1,9 @@
package com.cubetiqs.wsclient
import java.time.LocalDateTime
data class StockPrice (
val symbol: String,
val price: Double,
val time: LocalDateTime
)

View File

@@ -0,0 +1,6 @@
package com.cubetiqs.wsclient
import org.springframework.boot.autoconfigure.SpringBootApplication
@SpringBootApplication
class WsClientApplication

View File

@@ -0,0 +1 @@