如何增加Spring Sock.js WebSocket服务器实现的输出缓冲区 [英] How to increase output buffer for spring sockjs websocket server implementation

查看:294
本文介绍了如何增加Spring Sock.js WebSocket服务器实现的输出缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了sockjs websocket服务器的spring实现,无法通过8KB传输消息,以下是错误

I have used spring implementation of sockjs websocket server and unable to transmit message over 8KB, following is the error

2014-02-12 19:36:29,990 - org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession - DEBUG - SockJS session id=35n41xel was closed, CloseStatus [code=1009, reason=The decoded text message was too big for the output buffer and the endpoint does not support partial messages]

任何想法如何增加缓冲区大小

Any Idea how can I increase the buffer size

我使用了以下工厂,因为spring sockjs利用了tomcat容器(应用程序已部署在tomcat中,并且我还进行了调试以确认它确实使用了tomcat lib)

I used following factory as spring sockjs leverages tomcat container (App is deployed in tomcat and I also debugged to confirm that it indeed uses tomcat lib)

@Bean
public WebSocketContainerFactoryBean createWebSocketContainer() {
    WebSocketContainerFactoryBean container = new WebSocketContainerFactoryBean();
    container.setMaxTextMessageBufferSize(16384);
    container.setMaxBinaryMessageBufferSize(8192);
    return container;
}

然后我的URL映射看起来

And then my URL mapping looks

@Override 
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
    registry.addHandler(coBrowseSockJsCustomerHandler(), "/sockjs/cobrowse/customer/").withSockJS();}

我是否需要在某个地方设置带有sockjs的bean? sockjs如何知道它必须使用此facory?

Do I need to set this bean with sockjs somewhere? how does sockjs knows that it has to use this facory?

推荐答案

使用

Solved it by using clue from http://docs.spring.io/spring/docs/4.0.1.RELEASE/javadoc-api/index.html?org/springframework/web/socket/sockjs/SockJsService.html -got hold of ServletServerContainerFactoryBean and set the properties, this worked

@Bean
public ServletServerContainerFactoryBean createServletServerContainerFactoryBean() {
    ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean();
    container.setMaxTextMessageBufferSize(32768);
    container.setMaxBinaryMessageBufferSize(32768);
    logger.info("Websocket factory returned");
    return container;
}

这篇关于如何增加Spring Sock.js WebSocket服务器实现的输出缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆