Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve STOMP WebSocket documentation for input message buffer size #31616

Closed
monkeycode0 opened this issue Nov 17, 2023 · 5 comments
Closed
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: documentation A documentation task
Milestone

Comments

@monkeycode0
Copy link

monkeycode0 commented Nov 17, 2023

I send a message to the server from a web UI.

When the data size is greater than 64K, the server does not respond to the WEB client.

How can I change the max buffer size?

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
    @Bean
    public ServletServerContainerFactoryBean createWebSocketContainer() {
        ServletServerContainerFactoryBean factoryBean = new ServletServerContainerFactoryBean();
        factoryBean.setMaxBinaryMessageBufferSize(2*1024*1024);
        factoryBean.setMaxTextMessageBufferSize(2*1024*1024);
        factoryBean.setMaxSessionIdleTimeout(60 * 1000L);
        return factoryBean;
    }
}

I'd like to use this config, but it does not work.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 17, 2023
@sbrannen
Copy link
Member

I've edited your comment to improve the formatting. You might want to check out this Mastering Markdown guide for future reference.

@sbrannen sbrannen added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Nov 17, 2023
@monkeycode0
Copy link
Author

I've edited your comment to improve the formatting. You might want to check out this Mastering Markdown guide for future reference.

Thank you very much!

@rstoyanchev
Copy link
Contributor

Thanks for the report.

The above should adjust the input buffer size of a standard (JSR-356) WebSocket server. Separately, there is a size limit for incoming messages at the STOMP level that you can set through the configureWebSocketTransport callback of WebSocketMessageBrokerConfigurer. If you turn logging up, you'll look for indications whether the message is rejected at the WebSocket server or at the level of STOMP handling.

If this does not work, please share a small project.

@rstoyanchev rstoyanchev added the status: waiting-for-feedback We need additional information before we can continue label Nov 21, 2023
@monkeycode0
Copy link
Author

monkeycode0 commented Nov 22, 2023

Thanks for the report.

The above should adjust the input buffer size of a standard (JSR-356) WebSocket server. Separately, there is a size limit for incoming messages at the STOMP level that you can set through the configureWebSocketTransport callback of WebSocketMessageBrokerConfigurer. If you turn logging up, you'll look for indications whether the message is rejected at the WebSocket server or at the level of STOMP handling.

If this does not work, please share a small project.

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        config.enableSimpleBroker("/topic", "/direct");
        config.setApplicationDestinationPrefixes("/app");
    }

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/manager/{userId}", "/client/{userId}")
                .setAllowedOrigins("*")
                .setHandshakeHandler(new CustomHandshakeHandler())
        ;
    }

    @Override
    public void configureWebSocketTransport(WebSocketTransportRegistration registry) {
        registry.setMessageSizeLimit(128 * 1024 * 1024);
        registry.setSendBufferSizeLimit(128 * 1024 * 1024);
        registry.setSendTimeLimit(60 * 1000);
        WebSocketMessageBrokerConfigurer.super.configureWebSocketTransport(registry);
    }

}

yes, you are right! i override this method configureWebSocketTransport ,id does work!

when i use the gateway, it also should configure this:

spring: 
  cloud:
    gateway: 
      httpclient:
        websocket:
          max-frame-payload-length: 5242880

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Nov 22, 2023
@rstoyanchev
Copy link
Contributor

Good that it's working. I think the STOMP WebSocket Server section of the documentation could be improved a little based on this. Also the Server Configuration under WebSockets could also mention that with STOMP there is additional transport config.

@rstoyanchev rstoyanchev self-assigned this Nov 22, 2023
@rstoyanchev rstoyanchev added type: documentation A documentation task and removed status: waiting-for-triage An issue we've not yet triaged or decided on status: feedback-provided Feedback has been provided labels Nov 22, 2023
@rstoyanchev rstoyanchev added this to the 6.1.1 milestone Nov 22, 2023
@rstoyanchev rstoyanchev changed the title how to change data size when i use springboot-websocket to accept message? Improve STOMP WebSocket documentation for input message buffer size Nov 22, 2023
@github-actions github-actions bot added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-6.0.x labels Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: documentation A documentation task
Projects
None yet
Development

No branches or pull requests

4 participants