问题
I am implementing spring web-socket into our spring mvc web application. However I am running into message over size limits when I am trying to send a really big message to an endpoint.
I am getting the following error,
message:The 'content-length' header 68718 exceeds the configured message buffer size limit 65536
14:49:11,506 ERROR [org.springframework.web.socket.messaging.StompSubProtocolHandler] (http-localhost/127.0.0.1:8080-4) Failed to parse TextMessage payload=[13684590},..], byteCount=16384, last=true] in session vlsxdeol. Sending STOMP ERROR to client.: org.springframework.messaging.simp.stomp.StompConversionException: The 'content-length' header 68718 exceeds the configured message buffer size limit 65536
at org.springframework.messaging.simp.stomp.BufferingStompDecoder.checkBufferLimits(BufferingStompDecoder.java:148) [spring-messaging-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.messaging.simp.stomp.BufferingStompDecoder.decode(BufferingStompDecoder.java:124) [spring-messaging-4.1.6.RELEASE.jar:4.1.6.RELEASE]
Here is my configuration
@MessageMapping("/user/sockettest" )
@SendTo("/topic/sockettestresult")
public String sockAdd(ListId[] listIds) {
..
SecurityContextHolder.getContext().getAuthentication().getPrincipal();
return stringRet;
}
The xml config looks like the following
<websocket:simple-broker prefix="/topic"/>
<websocket:message-converters register-defaults="false">
<bean id="mappingJackson2MessageConverter" class="org.springframework.messaging.converter.MappingJackson2MessageConverter">
<property name="objectMapper" ref="objectMapper"></property>
</bean>
</websocket:message-converters>
</websocket:message-broker>
The client side code looks like this
function versionFiles() {
stompClient.send("/testbrkr/user/sockettest", {}, JSON.stringify(listIds));
}
Can you let me know what would be a good work-around.
Answer: If you know what would be the maximum size limit
<websocket:transport message-size="75536" send-buffer-size="75536"></websocket:transport>
I am looking on how to do partial messaging, will post it here as soon as I find out and get it working
回答1:
Consider <websocket:transport message-size=""/>
option for the <websocket:message-broker>
definition:
Configure the maximum size for an incoming sub-protocol message. For example a STOMP message may be received as multiple WebSocket messages or multiple HTTP POST requests when SockJS fallback options are in use.
The same can be achieved in annotation configuration using WebSocketMessageBrokerConfigurer.configureWebSocketTransport(WebSocketTransportRegistration)
implementation and with the setMessageSizeLimit()
on the matter.
回答2:
I was getting similar javascript errorr when the default value of 65kb was set.. then i set it to some random and again got some error like the
connection was interrupted
. So tried increasing the time limit and that worked for me. Actually when the limit exceeds, the messages are sent into packets/or frames, and while it was receiving the response from server, it timed out.
You can use tweak it as below
@EnableWebSocketMessageBroker
public class AppWebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
----
---
@Override
public void configureWebSocketTransport(WebSocketTransportRegistration registration) {
registration.setMessageSizeLimit(200000); // default : 64 * 1024
registration.setSendTimeLimit(20 * 10000); // default : 10 * 10000
registration.setSendBufferSizeLimit(3* 512 * 1024); // default : 512 * 1024
}
---
}
来源:https://stackoverflow.com/questions/34343235/stomp-spring-web-socket-message-exceeds-size-limit