Spring mvc 如何使用ConcurrentWebSocketSessionDecorator使用websocket发送邮件
我有一个并发问题,我的WebSocket被spring消息使用, 当我的聊天室有很多人时,它会非常慢 因此,我试图找到如何使用sendMessage的WebSocketSession具有同步类websocketServerSockJsSession的问题Spring mvc 如何使用ConcurrentWebSocketSessionDecorator使用websocket发送邮件,spring-mvc,spring-messaging,Spring Mvc,Spring Messaging,我有一个并发问题,我的WebSocket被spring消息使用, 当我的聊天室有很多人时,它会非常慢 因此,我试图找到如何使用sendMessage的WebSocketSession具有同步类websocketServerSockJsSession的问题 @Override public void sendMessageInternal(String message) throws SockJsTransportFailureException { // Open frame not s
@Override
public void sendMessageInternal(String message) throws SockJsTransportFailureException {
// Open frame not sent yet?
// If in the session initialization thread, then cache, otherwise wait.
if (!this.openFrameSent) {
synchronized (this.initSessionLock) {
if (!this.openFrameSent) {
this.initSessionCache.add(message);
return;
}
}
}
因此,如果他们在一秒钟内有200次聊天,速度会非常慢
我找到了WebSocketSession调用ConcurrentWebSocketSessionCorator的实现
但是我不能将WebSocketServerSocketJSSession强制转换为ConcurrentWebSocketSessionDecorator,我找不到如何设置我的WebSocketSession
我不能换袜子
那么,如果我使用sockJS并希望使用ConcurrentWebSocketSessionDecorator方法,我该怎么做呢
是实现ConcurrentWebSocketSessionDecorator sendMessage的另一种方法,还是我可以进行一些属性设置并使我的WebSocketSession转到ConcurrentWebSocketSessionDecorator
这是我的配置设置
@Configuration
@EnableWebMvc
@EnableWebSocket
public class SpringWebSocketConfig extends WebMvcConfigurerAdapter implements WebSocketConfigurer {
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
registry.addHandler(webSocketHandler(), "/websocket/send").addInterceptors(new HandshakeInterceptor()).setAllowedOrigins("*");
registry.addHandler(webSocketHandler(), "/websocket/sockjs").addInterceptors(new HandshakeInterceptor()).setAllowedOrigins("*").withSockJS();
}
顾名思义,
ConcurrentWebSocketSessionDecorator
是一个装饰器
此修饰符覆盖了一些函数,例如WebSocketSession
的sendMessage
,而WebSocketServerSockJSession
通过其WebSocketSession
执行其操作,因此将WebSocketSession
更改为concurrentwebsocketsessioncorator
可以解决此问题
ConcurrentWebSocketSessionDecorator currentWebSocketSessionDecorator = new ConcurrentWebSocketSessionDecorator (session, 1000, 1024);
wsSockJsSession.initializeDelegateSession((WebSocketSession)concurrentWebSocketSessionDecorator);