diff --git a/src/main/java/com/book/backend/global/stomp/WebSocketConfig.java b/src/main/java/com/book/backend/global/stomp/WebSocketConfig.java index 043d0ad..46e4c56 100644 --- a/src/main/java/com/book/backend/global/stomp/WebSocketConfig.java +++ b/src/main/java/com/book/backend/global/stomp/WebSocketConfig.java @@ -1,8 +1,10 @@ package com.book.backend.global.stomp; import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.messaging.simp.config.MessageBrokerRegistry; +import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.web.socket.config.annotation.EnableWebSocket; import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; import org.springframework.web.socket.config.annotation.StompEndpointRegistry; @@ -33,4 +35,14 @@ public void configureMessageBroker(final MessageBrokerRegistry registry) { registry.enableSimpleBroker("/sub")// 구독요청 .setHeartbeatValue(new long[]{0, 10000}); // 클라이언트로부터 10초마다 ping 받는것으로 소켓 연결 유지 } + + // heartbeat 처리를 위한 스케줄러 + @Bean + public ThreadPoolTaskScheduler taskScheduler() { + ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); + scheduler.setPoolSize(1); + scheduler.setThreadNamePrefix("wss-heartbeat-thread-"); + scheduler.initialize(); + return scheduler; + } }