diff options
author | Joffrey Bion <joffrey.bion@booking.com> | 2020-06-02 23:32:42 +0200 |
---|---|---|
committer | Joffrey Bion <joffrey.bion@booking.com> | 2020-06-02 23:32:42 +0200 |
commit | 7499004f643fadc73f385328dbfa75af7dcb3795 (patch) | |
tree | 7e6fed456b1c4409f2682335577164fcc7b40463 | |
parent | Update README with latest added features (diff) | |
download | seven-wonders-7499004f643fadc73f385328dbfa75af7dcb3795.tar.gz seven-wonders-7499004f643fadc73f385328dbfa75af7dcb3795.tar.bz2 seven-wonders-7499004f643fadc73f385328dbfa75af7dcb3795.zip |
Actually enable STOMP heart beats
3 files changed, 14 insertions, 3 deletions
diff --git a/sw-client/build.gradle.kts b/sw-client/build.gradle.kts index d932b57f..8671db0d 100644 --- a/sw-client/build.gradle.kts +++ b/sw-client/build.gradle.kts @@ -3,7 +3,7 @@ plugins { id("org.jlleitschuh.gradle.ktlint") } -val krossbowVersion = "0.20.3" +val krossbowVersion = "0.21.1" kotlin { jvm() diff --git a/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt b/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt index 8adbfa07..296bc72e 100644 --- a/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt +++ b/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt @@ -9,6 +9,7 @@ import kotlinx.serialization.builtins.list import kotlinx.serialization.builtins.serializer import org.hildan.krossbow.stomp.StompClient import org.hildan.krossbow.stomp.config.HeartBeat +import org.hildan.krossbow.stomp.config.HeartBeatTolerance import org.hildan.krossbow.stomp.conversions.kxserialization.StompSessionWithKxSerialization import org.hildan.krossbow.stomp.conversions.kxserialization.convertAndSend import org.hildan.krossbow.stomp.conversions.kxserialization.subscribe @@ -28,7 +29,8 @@ import org.luxons.sevenwonders.model.cards.PreparedCard class SevenWondersClient { private val stompClient = StompClient { - heartBeat = HeartBeat(10000, 15000) + heartBeat = HeartBeat(10000, 10000) + heartBeatTolerance = HeartBeatTolerance(0, 5000) } suspend fun connect(serverUrl: String): SevenWondersSession { diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/config/WebSocketConfig.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/config/WebSocketConfig.kt index dd4c4b15..1911f5b9 100644 --- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/config/WebSocketConfig.kt +++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/config/WebSocketConfig.kt @@ -5,6 +5,7 @@ import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration import org.springframework.messaging.simp.config.ChannelRegistration import org.springframework.messaging.simp.config.MessageBrokerRegistry +import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker import org.springframework.web.socket.config.annotation.StompEndpointRegistry import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer @@ -18,13 +19,21 @@ class WebSocketConfig( override fun configureMessageBroker(config: MessageBrokerRegistry) { // prefixes for all subscriptions - config.enableSimpleBroker("/queue", "/topic") + config.enableSimpleBroker("/queue", "/topic").apply { + setTaskScheduler(createTaskScheduler()) // to support heart beats + } config.setUserDestinationPrefix("/user") // /app for normal calls, /topic for subscription events config.setApplicationDestinationPrefixes("/app", "/topic") } + private fun createTaskScheduler() = ThreadPoolTaskScheduler().apply { + poolSize = 1 + threadNamePrefix = "stomp-heartbeat-thread-" + initialize() + } + override fun registerStompEndpoints(registry: StompEndpointRegistry) { registry.addEndpoint(SEVEN_WONDERS_WS_ENDPOINT) .setHandshakeHandler(handshakeHandler()) |