我的Spring 5 webflux websocket客户端在服务器发送大量消息时抛出异常。 有人能告诉我如何在客户端增加帧大小?
Flux<String> input = Flux.just(StrJSON);
WebSocketClient client = new ReactorNettyWebSocketClient();
client.execute(new URI(url),
session -> session
.send(input.map(session::textMessage))
.thenMany(
session.receive()
.map(t->t.getPayloadAsText())
.log()
)
.then()
).block();
间歇性例外:
io.netty.handler.codec.CorruptedFrameException: Max frame length of 65536 has been exceeded.
at io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder.protocolViolation(WebSocket08FrameDecoder.java:412)
at io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder.decode(WebSocket08FrameDecoder.java:277)
at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:489)
.....
答案 0 :(得分:0)
可能对您有所帮助。
根据此merge request,应将客户端设置为ReactorNettyWebSocketClient
类型,而不是接口WebSocketClient
。
然后您可以致电client.setMaxFramePayloadLength(maxFramePayload);
因此在您的代码中,您应该具有:
ReactorNettyWebSocketClient client = new ReactorNettyWebSocketClient();
client.setMaxFramePayloadLength(2097152);
client.execute(new URI(url),
session -> session
.send(input.map(session::textMessage))
.thenMany(
session.receive()
.map(t->t.getPayloadAsText())
.log()
)
.then()
).block();