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