stomp网络断开时候,15s后断开连接
This commit is contained in:
parent
a93864d985
commit
47508f9294
|
@ -3,14 +3,12 @@ package com.rax.vital.config;
|
|||
import com.rax.vital.interceptor.WSChannelInterceptor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.simp.config.ChannelRegistration;
|
||||
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
|
||||
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
|
||||
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;
|
||||
import org.springframework.web.socket.messaging.StompSubProtocolErrorHandler;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSocketMessageBroker
|
||||
|
@ -23,48 +21,16 @@ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
|
|||
public void registerStompEndpoints(StompEndpointRegistry registry) {
|
||||
registry.addEndpoint("/rax/chat", "/rax/ai-medicine", "/rax/doctor-medicine", "/rax/vital-signs", "/rax/SurgeryData")
|
||||
.setAllowedOrigins("*");
|
||||
// 错误处理
|
||||
registry.setErrorHandler(new StompSubProtocolErrorHandler() {
|
||||
/**
|
||||
*
|
||||
* @param clientMessage the client message related to the error, possibly
|
||||
* {@code null} if error occurred while parsing a WebSocket message
|
||||
* @param ex the cause for the error, never {@code null}
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Message<byte[]> handleClientMessageProcessingError(Message<byte[]> clientMessage, Throwable ex) {
|
||||
return super.handleClientMessageProcessingError(clientMessage, ex);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param errorMessage the error message, never {@code null}
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Message<byte[]> handleErrorMessageToClient(Message<byte[]> errorMessage) {
|
||||
return super.handleErrorMessageToClient(errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param errorHeaderAccessor
|
||||
* @param errorPayload
|
||||
* @param cause
|
||||
* @param clientHeaderAccessor
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected Message<byte[]> handleInternal(StompHeaderAccessor errorHeaderAccessor, byte[] errorPayload, Throwable cause, StompHeaderAccessor clientHeaderAccessor) {
|
||||
return super.handleInternal(errorHeaderAccessor, errorPayload, cause, clientHeaderAccessor);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureMessageBroker(MessageBrokerRegistry registry) {
|
||||
registry.enableSimpleBroker("/topic");
|
||||
long [] heartbeat = {10000, 5000};
|
||||
ThreadPoolTaskScheduler te = new ThreadPoolTaskScheduler();
|
||||
te.setPoolSize(1);
|
||||
te.setThreadNamePrefix("wss-heartbeat-thread-");
|
||||
te.initialize();
|
||||
registry.enableSimpleBroker("/topic").setTaskScheduler(te).setHeartbeatValue(heartbeat);
|
||||
registry.setApplicationDestinationPrefixes("/front");
|
||||
registry.setUserDestinationPrefix("/topic/user");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user