【问题标题】:Stomp over websocket : The send buffer size exceeded the allowed limitStomp over websocket:发送缓冲区大小超过了允许的限制
【发布时间】:2014-12-20 01:18:38
【问题描述】:

在客户端我使用 Stomp 进行 websocket 连接和服务器端我使用 Spring 4 它客户端我做了配置

var socket = new SockJS(urlBase + "/" + contextroot+'/hello');
stompClient = Stomp.over(socket);

以下代码每 2 秒执行一次以向服务器发送数据

stompClient.send('/app/sendRequest/'+indexVal, {}, 
JSON.stringify({index : simIndex}));

服务器响应下面的队列

stompClient.subscribe('/queue/response', processResponseObj);

在服务器端配置完成

<websocket:message-broker application-destination-prefix="/app">
   <!--<websocket:transport send-timeout="15000" message-size="1051648" send-buffer-size="1051648"/> -->
   <websocket:stomp-endpoint path="/hello">
       <websocket:sockjs />
   </websocket:stomp-endpoint>
   <websocket:stomp-broker-relay prefix="/topic, /queue"  />

    <websocket:message-converters>
        <beans:bean class="org.springframework.messaging.converter.MappingJackson2MessageConverter">
        <beans:property name="objectMapper" ref="objectMapper" />
       </beans:bean>
    </websocket:message-converters>

    </websocket:message-broker>

消息在服务器端响应

 messagingTemplate.convertAndSend("/queue/response",obj);

几秒钟后我收到错误消息

2014-10-24 16:39:33,869 ERROR et.messaging.SubProtocolWebSocketHandler: 330 - Terminating session id 'dkbzrkxp'
org.springframework.web.socket.handler.SessionLimitExceededException: The send buffer size 1147188 bytes for session 'dkbzrkxp exceeded the allowed limit 1051648
    at org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator.sessionLimitReached(ConcurrentWebSocketSessionDecorator.java:162) ~[ConcurrentWebSocketSessionDecorator.class:4.0.6.RELEASE]
    at org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator.checkSessionLimits(ConcurrentWebSocketSessionDecorator.java:150) ~[ConcurrentWebSocketSessionDecorator.class:4.0.6.RELEASE]
    at org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator.sendMessage(ConcurrentWebSocketSessionDecorator.java:105) ~[ConcurrentWebSocketSessionDecorator.class:4.0.6.RELEASE]
    at org.springframework.web.socket.messaging.StompSubProtocolHandler.handleMessageToClient(StompSubProtocolHandler.java:276) ~[StompSubProtocolHandler.class:4.0.6.RELEASE]
    at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.handleMessage(SubProtocolWebSocketHandler.java:326) ~[SubProtocolWebSocketHandler.class:4.0.6.RELEASE]
    at org.springframework.messaging.support.ExecutorSubscribableChannel$1.run(ExecutorSubscribableChannel.java:70) [ExecutorSubscribableChannel$1.class:4.0.6.RELEASE]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_20]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_20]
    at java.lang.Thread.run(Unknown Source) [na:1.8.0_20]
2014-10-24 16:39:33,871  WARN ort.session.WebSocketServerSockJsSession: 285 - Failed to send SockJS close frame: The remote endpoint was in state [TEXT_PARTIAL_WRITING] which is an invalid state for called method
2014-10-24 16:39:33,875 ERROR et.messaging.SubProtocolWebSocketHandler: 330 - Terminating session id 'nro1ww4x'
org.springframework.web.socket.handler.SessionLimitExceededException: The send buffer size 1147188 bytes for session 'nro1ww4x exceeded the allowed limit 1051648
    at org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator.sessionLimitReached(ConcurrentWebSocketSessionDecorator.java:162) ~[ConcurrentWebSocketSessionDecorator.class:4.0.6.RELEASE]
    at org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator.checkSessionLimits(ConcurrentWebSocketSessionDecorator.java:150) ~[ConcurrentWebSocketSessionDecorator.class:4.0.6.RELEASE]
    at org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator.sendMessage(ConcurrentWebSocketSessionDecorator.java:105) ~[ConcurrentWebSocketSessionDecorator.class:4.0.6.RELEASE]
    at org.springframework.web.socket.messaging.StompSubProtocolHandler.handleMessageToClient(StompSubProtocolHandler.java:276) ~[StompSubProtocolHandler.class:4.0.6.RELEASE]
    at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.handleMessage(SubProtocolWebSocketHandler.java:326) ~[SubProtocolWebSocketHandler.class:4.0.6.RELEASE]
    at org.springframework.messaging.support.ExecutorSubscribableChannel$1.run(ExecutorSubscribableChannel.java:70) [ExecutorSubscribableChannel$1.class:4.0.6.RELEASE]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_20]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_20]
    at java.lang.Thread.run(Unknown Source) [na:1.8.0_20]
2014-10-24 16:39:33,876  WARN ort.session.WebSocketServerSockJsSession: 285 - Failed to send SockJS close frame: The remote endpoint was in state [TEXT_PARTIAL_WRITING] which is an invalid state for called method
2014-10-24 16:39:34,833 ERROR standard.StandardWebSocketHandlerAdapter:  55 - Closing due to exception for WebSocket session id=0

我也尝试增加缓冲区大小,但一段时间后它给出了同样的异常。一旦达到缓冲区大小。

我认为 websocket 会话缓冲区在消息传递后不会释放。

是否有任何设置要求? 我错过了任何配置吗?

【问题讨论】:

  • 你解决了这个问题吗?我面临同样的问题
  • 添加registration.setMessageSizeLimit(102400* 1024);解决

标签: stomp spring-4 spring-websocket


【解决方案1】:

添加解决

 public void configureWebSocketTransport(WebSocketTransportRegistration registration) {
registration.setMessageSizeLimit(102400* 1024); 
}

【讨论】:

  • 这不是一个答案,这充其量是不完整的。你在哪里添加的?!
  • 遇到同样的错误,我尝试了上述方法,但没有运气。有关如何解决此问题的任何帮助? "会话 '5s41tqiq' 的缓冲区大小 4206421 字节超出了允许的限制 4194304""
【解决方案2】:

尝试在服务器端配置 web socket。 在 WebSocketConfig 类中是这样的:

 public void configureWebSocketTransport(WebSocketTransportRegistration registration) {
    registration.setMessageSizeLimit(500 * 1024);
    registration.setSendBufferSizeLimit(1024 * 1024);
    registration.setSendTimeLimit(20000);
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2013-05-08
  • 2021-02-25
  • 2016-03-24
  • 1970-01-01
  • 2012-12-31
  • 1970-01-01
  • 2022-11-11
  • 1970-01-01
相关资源
最近更新 更多