Java – spring stomp over websocket: message / buffer / cache / stream limit

I can't understand my different parameters in the websocket configuration for developing chat applications involving images / videos:

I noticed that sockjs in the web page sends messages with a frame size of 16K I also tested the message size limit, which determines the maximum size of messages I can transmit

Can you let me know what it is:

>Stream byte limit > send buffer size limit > HTTP message cache size > What are some messages and how to use them? Are they useful here? > In addition, I plan to set the maximum image / video size to 2GB and expect about 100 concurrent users when publishing

Can you tell us which sizes should be kept and why? What are the default values? And how does everyone affect the performance of my chat application?

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {

@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
    registry.addEndpoint("/stomp").withSockJS()
            .setStreamBytesLimit(15 * 1024)
            .setHttpMessageCacheSize(15 * 1024);
}

@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
    registry.enableSimpleBroker("/queue/","/topic/","/exchange/");
    registry.setApplicationDestinationPrefixes("/app");
}

@Override
public void configureWebSocketTransport(WebSocketTransportRegistration registration) {
    registration.setSendTimeLimit(15 * 1000)
            .setSendBufferSizeLimit(1 * 1024)
            // max message size 2GB (2048 bytes) : default is 64KB
            .setMessageSizeLimit(2 * 1024 * 1024);
}

}

Solution

Answer questions with my findings and Implementation:

In the following configurations:

@Override
public void configureWebSocketTransport(WebSocketTransportRegistration registration) {
    registration.setSendTimeLimit(60 * 1000)
            .setSendBufferSizeLimit(200 * 1024 * 1024)
            .setMessageSizeLimit(200 * 1024 * 1024);
}

>Stream byte limit: information from source

/**
 * Streaming transports save responses on the client side and don't free
 * memory used by delivered messages. Such transports need to recycle the
 * connection once in a while. This property sets a minimum number of bytes
 * that can be send over a single HTTP streaming request before it will be
 * closed. After that client will open a new request. Setting this value to
 * one effectively disables streaming and will make streaming transports to
 * behave like polling transports.
 * <p>The default value is 128K (i.e. 128 * 1024).
 */
public SockJsServiceRegistration setStreamBytesLimit(int streamBytesLimit) {
    this.streamBytesLimit = streamBytesLimit;
    return this;
}

>The send buffer size limit defaults to 512KB If the message is sent slowly, subsequent messages will be buffered until sendtimelimit or sendbuffersizelimit. > HTTP message cache size: information from source

/**
 * The number of server-to-client messages that a session can cache while waiting for
 * the next HTTP polling request from the client. All HTTP transports use this
 * property since even streaming transports recycle HTTP requests periodically.
 * <p>The amount of time between HTTP requests should be relatively brief and will not
 * exceed the allows disconnect delay (see
 * {@link #setDisconnectDelay(long)}),5 seconds by default.
 * <p>The default size is 100.
 */
public SockJsServiceRegistration setHttpMessageCacheSize(int httpMessageCacheSize) {
    this.httpMessageCacheSize = httpMessageCacheSize;
    return this;
}

>What are partial messages and how to use them? Are they useful here? Still not sure how to stream large files through websocket and use partial messaging (decided to use HTTP instead) > in addition, about 100 concurrent users are expected at the time of publication. = > Set by messagesizelimit and use HTTP for file upload / streaming media download You can also use Apache file upload config to set server restrictions:

@Bean
public CommonsMultipartResolver multipartResolver() {
    CommonsMultipartResolver resolver = new CommonsMultipartResolver();
    resolver.setMaxUploadSize(2 * 1024 * 1024 * 1024); // 2 GB limit set for file upload
    resolver.setdefaultencoding("utf-8");
    return resolver;

}

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>