Hello, The tomcat web container websocket buffer size limit is 8kb, Use ServletServerContainerFactoryBean can be adjusted to 64kb. But it does not support Stomp. I have searched various materials to modify the limit, but all failed. Please give me some guidance, thank you!
@Configuration
public class MyServerContainerConfigurer{
@Bean
public ServletServerContainerFactoryBean createWebSocketContainer() {
ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean();
container.setMaxTextMessageBufferSize(64*1024);
container.setMaxBinaryMessageBufferSize(64*1024);
return container;
}
}
Effective in normal mode, as shown in the following example.
@Configuration
@EnableWebSocket
public class MyWebSocketConfigurer implements WebSocketConfigurer {
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
registry.addHandler(new TextWebSocketHandler(),"/endpoint").setAllowedOrigins("*");
}
}
It is invalid in Stomp mode, Example of Stomp.
@Configuration
@EnableWebSocketMessageBroker
public class MyWebSocketMessageBrokerConfigurer implements WebSocketMessageBrokerConfigurer {
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/portfolio").setAllowedOrigins("*");
}
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.setPathMatcher(new AntPathMatcher("."));
config.setApplicationDestinationPrefixes("/app");
config.enableSimpleBroker("/topic", "/queue");
}
@Override
public void configureWebSocketTransport(WebSocketTransportRegistration webSocketTransportRegistration) {
webSocketTransportRegistration
.setMessageSizeLimit(1024 * 1024)
.setSendBufferSizeLimit(1024 * 1024 );
}
}
Error log
2020-06-16 13:45:51.226 DEBUG 11628 --- [nio-8080-exec-4] s.w.s.h.LoggingWebSocketHandlerDecorator : StandardWebSocketSession[id=c11461a9-8340-e006-dda9-cf50716694dd, uri=ws://localhost:8080/portfolio] closed with CloseStatus[code=1009, reason=No async message support and buffer too small. Buffer size: [8,192], Message size: [11,020]]
SpringBoot Version : 2.3.0
Comment From: rstoyanchev
@liyiorg did you find anything more? The above should work. I am going to close this here, as we now also have #31616, which is on the same issue. Please, feel free to comment there while we investigate, or here if needed.