fix:STOMP定义心跳0,10000

This commit is contained in:
wangff
2025-09-19 14:41:37 +08:00
parent 190ee8a5c1
commit 8f7a044d28

View File

@@ -1,14 +1,11 @@
package com.cool.store.config.websocket;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.simp.config.ChannelRegistration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.messaging.simp.stomp.StompCommand;
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
import org.springframework.messaging.support.ChannelInterceptor;
import org.springframework.scheduling.TaskScheduler;
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;
@@ -36,11 +33,22 @@ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
// 配置消息代理
registry.enableSimpleBroker("/topic", "/queue"); // 启用简单代理,用于广播和点对点消息
registry.enableSimpleBroker("/topic", "/queue") // 启用简单代理,用于广播和点对点消息
.setHeartbeatValue(new long[]{0, 10000})
.setTaskScheduler(webSocketTaskScheduler());
registry.setApplicationDestinationPrefixes("/app"); // 设置应用程序端点前缀
// registry.setUserDestinationPrefix("/user");
}
@Bean
public TaskScheduler webSocketTaskScheduler() {
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.setPoolSize(1);
taskScheduler.setThreadNamePrefix("websocket-heartbeat-");
taskScheduler.initialize();
return taskScheduler;
}
// @Override
// public void configureClientInboundChannel(ChannelRegistration registration) {
// registration.interceptors(new ChannelInterceptor() {