From 7499004f643fadc73f385328dbfa75af7dcb3795 Mon Sep 17 00:00:00 2001 From: Joffrey Bion Date: Tue, 2 Jun 2020 23:32:42 +0200 Subject: Actually enable STOMP heart beats --- .../org/luxons/sevenwonders/server/config/WebSocketConfig.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'sw-server/src/main/kotlin/org') 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()) -- cgit