编程语言
首页 > 编程语言> > java – Spring Stomp over Websocket:消息/缓冲区/缓存/流限制

java – Spring Stomp over Websocket:消息/缓冲区/缓存/流限制

作者:互联网

无法理解我在用于开发涉及图像/视频的聊天应用程序的websocket配置中的不同参数:

我注意到网页中的SockJs发送帧大小为16K的消息.我还测试了消息大小限制是什么决定了我可以传输的消息的最大大小.

能不能让我知道是什么:

>流字节限制
>发送缓冲区大小限制
> http消息缓存大小
>什么是部分消息以及如何使用它们,它们在这里有用吗?
>此外,我计划将图像/视频的最大大小设置为2GB,并在发布时预计大约100个并发用户.

您能告诉我们应该保留哪些尺寸以及为什么?什么是默认值?以及每个人如何影响我的聊天应用程序的性能?

@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);
}

}

解决方法:

用我的发现和实施回答问题:

在以下配置中:

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

>流字节限制:来自源的信息

/**
 * 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;
}

>发送缓冲区大小限制
默认值为512KB.如果消息发送很慢,则会缓冲后续消息,直到达到sendTimeLimit或sendBufferSizeLimit.
> http消息缓存大小:来自源的信息

/**
 * 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;
}

>什么是部分消息以及如何使用它们,它们在这里有用吗?
仍不确定如何通过websocket流式传输大型文件并使用部分消息传递(决定使用HTTP代替)
>此外,我计划将图像/视频的最大大小设置为2GB,并在发布时预计大约100个并发用户.
=&GT由messageSizeLimit设置
并使用HTTP进行文件上传/流媒体下载.还使用apache file-upload config设置服务器限制:

@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;

}

标签:spring-websocket,java,spring,stomp,sockjs
来源: https://codeday.me/bug/20190727/1554745.html