STOMP Spring WebSocket消息超出大小限制 [英] STOMP Spring WebSocket message exceeds size limit
问题描述
我正在将Spring WebSocket实现到我们的Spring MVC Web应用程序中.但是,当我尝试向端点发送非常大的消息时,我遇到了超出大小限制的消息.
I am implementing Spring WebSocket 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.
我遇到以下错误:
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]
这是我的配置:
@MessageMapping("/user/sockettest" )
@SendTo("/topic/sockettestresult")
public String sockAdd(ListId[] listIds) {
..
SecurityContextHolder.getContext().getAuthentication().getPrincipal();
return stringRet;
}
xml配置如下所示:
The xml config looks like the following:
<websocket:stomp-endpoint path="/user/sockettest">
<websocket:sockjs/>
</websocket:stomp-endpoint>
<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>
客户端代码如下:
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
推荐答案
考虑< websocket:message的
定义:< websocket:transport message-size ="/>
选项-broker>
Consider <websocket:transport message-size=""/>
option for the <websocket:message-broker>
definition:
配置传入的子协议消息的最大大小.例如,可以将STOMP消息作为多个WebSocket消息接收或使用SockJS后备选项时出现多个HTTP POST请求.
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.
使用 WebSocketMessageBrokerConfigurer.configureWebSocketTransport(WebSocketTransportRegistration)
实现以及此问题上的 setMessageSizeLimit()
,可以在批注配置中实现相同的目的.
The same can be achieved in annotation configuration using WebSocketMessageBrokerConfigurer.configureWebSocketTransport(WebSocketTransportRegistration)
implementation and with the setMessageSizeLimit()
on the matter.
这篇关于STOMP Spring WebSocket消息超出大小限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!