Issue with WebSocket transport compression for RSocket
See original GitHub issueUnable to make WebSocket transport compression work in RSocket client/server Spring Boot applications running with Netty backend and Spring Boot version 2.5.9.
The Spring Boot allows to specify the server-side RSocket transport and endpoint path in the application.properties, but there are no any additional configuration parameters available besides that. The autoconfig creates an instance of the RSocketWebSocketNettyRouteProvider
which doesn’t have compression enabled and also doesn’t have any customizers to enable it.
To get around that I removed spring.rsocket.server.mapping-path
property and declared a bean like this in the server config to pass a WebsocketServerSpec
with compress option enabled to httpServerRoutes.ws(...)
call:
@Bean
NettyRouteProvider rSocketWebsocketRouteProvider(
RSocketProperties properties, RSocketMessageHandler messageHandler,
ObjectProvider<RSocketServerCustomizer> customizers) {
return new NettyRouteProvider() {
public HttpServerRoutes apply(HttpServerRoutes httpServerRoutes) {
RSocketServer server = RSocketServer.create(messageHandler.responder());
customizers.forEach((customizer) -> customizer.customize(server));
return httpServerRoutes.ws("/rsocket",
WebsocketRouteTransport.newHandler(server.asConnectionAcceptor()),
WebsocketServerSpec.builder().compress(true).build());
}
};
}
On the client side I’m creating RSocketRequester
like this:
RSocketRequester requester = builder
.setupRoute("/backend/connect")
.setupData(id)
.rsocketConnector(connector -> connector
.reconnect(Retry.fixedDelay(Integer.MAX_VALUE, Duration.ofSeconds(5)))
.acceptor(RSocketMessageHandler.responder(strategies, backendController)) // ****** (1)
)
.dataMimeType(MediaType.APPLICATION_JSON)
.transport(() -> {
// httpClient is immutable - baseUrl() creates a copy
ClientTransport t = WebsocketClientTransport.create(
HttpClient.create().baseUrl(backendUrl), "/rsocket")
.webSocketSpec(configurer -> configurer
.compress(true) // ****** (2)
.maxFramePayloadLength(65536));
return t.connect();
});
The webSocketSpec
need to have compress flag enabled. Otherwise I don’t see compression applied when looking at the traffic in Charles proxy with a simple port forwarding enabled.
The problem is that when compress is enabled on line (2) the client can’t complete the connection sequence.
However if I comment out the .acceptor()
configuration on line (1) the connect is working and I see server to client calls going through and I can see data is being compressed. But without the acceptor server can’t call the client.
Here is an example project repository https://github.com/maximdim/rsocket2/tree/rsocket-compression
You can launch BackendApplication
and AgentApplication
to observe described issue.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (5 by maintainers)
@ekuleshov apologies for the delay. I have been able to reproduce this and the issue seems to be related to the client acceptor not being able to read anything from the
SETUP
payload. This is for any client acceptor, and it’s reproducible with just RSocket Java. I’ve created https://github.com/rsocket/rsocket-java/issues/1045 to supersede this one.Thanks for the report!
Please see my
rSocketWebsocketRouteProvider()
bean override that enables server-side compression. But with that stuff enabled I was unable to confirm compression working between client and server.The #29550 issue is about removing the need in such override and allowing to configure server-side compression with autoconfig, server properties, etc… But the compression either does not work or my configuration change is not correct one.