java buffersize 单位,Java SockJS Spring客户端和消息大小

使用SockJS java客户端,我正在尝试连接到Spring sockjs服务器,并且获得了大约20Kb的消息(没有标头)的错误1009. Javascript库工作正常.

Transport closed with CloseStatus[code=1009, reason=The decoded text message was too big

for the output buffer and the endpoint does not support partial messages] in WebSocketClientSockJsSession

[id='9fa30eb453e14a8c8612e1064640646a, url=ws://127.0.0.1:8083/user]

我在服务器上有几个配置类(如果我配置这些东西的次数超过必要的话,我现在还不知道):

@Configuration

@EnableWebSocket

public class WebSocketTransportConfig implements WebSocketConfigurer {

// Important web socket setup. If big message is coming through, it may overflow the buffer and this will lead in disconnect.

// All messages that are coming through normally (including snapshots) must be order of magnitude smaller, or connection will be broken

// sometimes

// There is also MaxBinaryMessageSize that we do not employ as we use Stomp, but for completeness it is also set to same values.

// Javadoc http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/socket/adapter/jetty/JettyWebSocketSession.html#setTextMessageSizeLimit-int-

public static final int MAX_TEXT_MESSAGE_SIZE = 2048000; // 2 Megabytes.

public static final int BUFFER_SIZE = MAX_TEXT_MESSAGE_SIZE * 5;

private static final Logger LOGGER = LogManager.getLogger(WebSocketTransportConfig.class);

@Override

public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {

}

@Bean

public DefaultHandshakeHandler handshakeHandler() {

LOGGER.info("Websocket buffer size: " + BUFFER_SIZE + " bytes.");

WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);

policy.setMaxTextMessageBufferSize(BUFFER_SIZE);

policy.setMaxTextMessageSize(MAX_TEXT_MESSAGE_SIZE);

policy.setMaxBinaryMessageBufferSize(BUFFER_SIZE);

policy.setMaxBinaryMessageSize(MAX_TEXT_MESSAGE_SIZE);

policy.setInputBufferSize( BUFFER_SIZE);

policy.setIdleTimeout(600000);

return new DefaultHandshakeHandler(

new JettyRequestUpgradeStrategy(new WebSocketServerFactory(policy)));

}

}

@Configuration

@EnableWebSocketMessageBroker

@EnableScheduling

public class WebSocketBrokerConfig extends WebSocketMessageBrokerConfigurationSupport implements WebSocketMessageBrokerConfigurer {

@Override

public void configureWebSocketTransport(WebSocketTransportRegistration registry) {

// Increase buffers.

// Too little buffers may result in fatal errros when transmitting relatively large messages.

registry.setMessageSizeLimit(WebSocketTransportConfig.MAX_TEXT_MESSAGE_SIZE);

registry.setSendBufferSizeLimit(WebSocketTransportConfig.BUFFER_SIZE);

super.configureWebSocketTransport(registry);

}

}

根据Stomp spring web socket message exceeds size limit应该有帮助,但在连接Java Spring SockJS客户端时,我仍然得到错误1009(太大的消息).

因此我怀疑我可能有以下两个问题之一:

> Java SockJS客户端也必须配置为RECEIVE更大的消息.

>或者,我仍然在服务器上配置错误.

如何在Java SockJS Spring客户端上增加缓冲区大小?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值